While trying to add the value i.e. American express to the vendor field, the code is not working

111 views Asked by At
    List<ListOrRecordRef> List = new List<ListOrRecordRef>();
    ListOrRecordRef RecordRefItem = new ListOrRecordRef();
    RecordRefItem.name = "American Express";
    RecordRefItem.internalId = "898";
    RecordRefItem.typeId = "394";
    List.Add(RecordRefItem);
    rec.customFieldList = List.ToArray();

    WriteResponse response = service.add(rec);

The code is used to add multiselect option of vendor. ex : american express

2

There are 2 answers

7
Marcin On

First of all like Heinz Siahaan said: 'List' is a keyword in C# so you can't create variable with this name.

Second:

ListOrRecordRef RecordRefItem = new ListOrRecordRef();

I'm not sure but name of this method suggest that this line of code creates list of records not one item so you can't use something like this:

RecordRefItem.name = "American Express";

but you should try :

RecordRefItem[i].name = "American Express";

where i is and index of element, but before access it you must create it

0
AudioBubble On

found a way its working fine://Note that for multi select option to set we have to take two class:ListOrRecordRef mention the id of the 898:American express&
//SelectCustomFieldRef to mention the field ListOrRecordRef recordRefItem = new ListOrRecordRef(); recordRefItem.internalId = "898"; SelectCustomFieldRef scfr = new SelectCustomFieldRef(); scfr.scriptId = "custrecord_from_so_customer"; scfr.value = recordRefItem;//set the object value to the mentioned field customFieldArray[1] = scfr; rec.customFieldList = customFieldArray