Import Optional fields using Interop SDK for AR

SUGGESTED

Hi, Can any one help on this optional field in .Net API

Problem: Optional field can't be inserted. Only the tick mark can be viewed in AR invoice entry UI screen

Source code:

ARINVOICE1detail4.RecordClear();
ARINVOICE1detail4.RecordCreate(ViewRecordCreate.NoInsert);
ARINVOICE1detail4.Process();
ARINVOICE1detail4.Fields.FieldByName("CNTLINE").SetValue(0, false);
ARINVOICE1detail4.Fields.FieldByName("OPTFIELD").SetValue("YEAR", false);
////ARINVOICE1detail4.Read(false);
ARINVOICE1detail4.Fields.FieldByName("VALIFTEXT").SetValue("2021", false);
ARINVOICE1detail4.Insert();
ARINVOICE1detail4.Read(true);
ARINVOICE1detail4.RecordCreate(0);

  • 0
    SUGGESTED

    Assuming that your view compositions are correct, the code below should give you some ideas.  You'll have to adapt it to your language but the function calls below show you how to look for an existing optional field record and create it if required. 

    DetailOptFld is the view, aOptField is the optional field code, and aValue is the value to assign to the optional field.  In my code it is a variant data type which is why I use the fancy VALINDEX field value to figure out which field to assign the value to.


        With DetailOptFld
            .RecordClear
            .Fields("OPTFIELD").PutWithoutVerification aOptField

            If Not (.Read) Then
                .RecordCreate VIEW_RECORD_CREATE_DELAYKEY
                .Fields("OPTFIELD").value = aOptField
                .Fields("SWSET").value = "1"
            End If

            .Fields.FieldByID(.Fields("VALINDEX").value) = aValue

            If .Exists Then
                .Update
            Else
                .Insert
            End If

        End With
  • 0
    SUGGESTED

    I've got the C# code for this as I did just the same yesterday. Django is correct though as you need to set the swset value and then before you insert check the exists value. If true then call update instead. You don't need to set cntline. I don't use the valindex field but I'll check that out later. I'll be back online here later today

  • 0 in reply to Django

    thank you django

  • 0 in reply to Vega

    Thank you Vega

  • 0 in reply to Django

    Nice. I didn't know that about VALINDEX. So once you have told the view which optional field you are dealing with, you try a read and if it is false, you do the record create, then set the field and the SWSET values, then query which field needs to be populated on the view for that optional field and set its value accordingly, then insert or update. I like that.

  • 0 in reply to Eugine

    Hi Eugine, if either of the above suggested answers helped, please do mark them as verified White check mark for the benefit of others in this forum :). Thank you!

    Also, if you have a minute, tell us about your great experience on Sage City, take this short survey