0

I'm trying to set a value for the sublist 'addressbookaddress'. But the script fail with error. However, I'm able to get the subrecord value.

Error:

Not supported on the current subrecord: CurrentSubrecord.setValue.

Executed code:

/**
*@NApiVersion 2.0
*@NScriptType ClientScript
*/
define(["N/currentRecord"], function(currentRecord){

/*
    Copy phone number from vendor to address, when creating a new sublist entry
*/
var lineInit = function(context) { 
    var record = context.currentRecord;
    var sublistId = context.sublistId;

    var subrecord = record.getCurrentSublistSubrecord({
        sublistId: sublistId,
        fieldId: 'addressbookaddress'
    });

    if (!subrecord) {
        return;
    }

    var address = subrecord.getValue({
        fieldId: 'addr1'
    });

    subrecord.setValue({
        fieldId: 'addr1',
        value: 'test'
    });

    return;
}

return {
    lineInit: lineInit,
}

});
J Net
  • 3
  • 3

1 Answers1

2

Client scripts have read-only access to subrecords.

A client script can be deployed on the Address form. Using values from the entryformquerystring one can search for the parent record.

Maria Berinde-Tampanariu
  • 1,011
  • 1
  • 12
  • 25
  • So it's not possible to achieve what I'm trying to do or do you have any suggestion of a workaround? – J Net Jan 14 '18 at 18:45
  • Perhaps you can achieve the same functionality with a client script attached to the address form. – Maria Berinde-Tampanariu Jan 14 '18 at 18:46
  • Unfortunately it's not possible to attach to the address form. I can't find it as an option in the "APPLIES TO" list. – J Net Jan 14 '18 at 19:54
  • It is possible, but it works a bit differently. Go to Customization > Forms > Address Forms, Customize/Edit the Address Form and enter the script file under Custom Code. – Maria Berinde-Tampanariu Jan 14 '18 at 19:56
  • Cool, that actually works. But how do I then access something on the parent? Because that is were I should source the value, from the Vendor record. – J Net Jan 14 '18 at 20:26
  • One option is to get the value of the hidden field entryformquerystring and use the entityid from this value to search for the vendor and get the email address. – Maria Berinde-Tampanariu Jan 14 '18 at 21:01
  • It seems like "entryformquerystring" isn't available on the record. – J Net Jan 14 '18 at 21:14
  • How did you try to get the field value? I tested creating a custom field and setting {entryformquerystring} as the default value (formula). That worked, so I expected getting the value by script would also work. Otherwise, can you create a field, as well? – Maria Berinde-Tampanariu Jan 14 '18 at 21:15
  • Okay, now I understand your idea of solving this. I created the field and can access it but it seems like defaulting to {entryformquerystring} doesn't work as formula. I get the following error if I enter the string in "Default value" and click the arrow to open formula view: "formula=ERROR: Recursive Reference&target=VALIDATION_form.defaultvalue" – J Net Jan 14 '18 at 21:34
  • Not sure why. I don't think that I opened the formula view. I just pasted the value and made sure the formula checkbox was checked. – Maria Berinde-Tampanariu Jan 14 '18 at 21:36
  • I did exactly that now but the field ended up empty. `record.getValue({ fieldId: 'hidden_entryformquerystring' }); ""` Did you do anything else that could make a difference? – J Net Jan 14 '18 at 21:42
  • I would have expected the field you created to have a different ID, which starts with custrecord. Could you use that ID as fieldID? On a different note, does `record.getValue({ fieldId: 'entryformquerystring' });` return any value? – Maria Berinde-Tampanariu Jan 14 '18 at 21:46
  • I just shortened it to make it more readable :) It is called custrecord_hidden_entryformquerystr. Making the request you mentioned with the id custrecord_hidden_entryformquerystr return an empty string "" – J Net Jan 14 '18 at 21:51
  • Oh ok. Can you temporarily display the field on the address form and see if it is populated? Is the field stored? It shouldn't be stored. – Maria Berinde-Tampanariu Jan 14 '18 at 21:52
  • Changed Display Type to "Normal" and it is visible on the Address form. So it is created only the defaulting isn't working. – J Net Jan 14 '18 at 21:59
  • What type of field did you use? I used Free-Form Text. – Maria Berinde-Tampanariu Jan 14 '18 at 22:01
  • So did I. Are you viewing or editing the address record when testing? – Maria Berinde-Tampanariu Jan 14 '18 at 22:05
  • Sorry, I found the issue. I did check out the "STORE VALUE" but apparently something did go wrong. Now I did it again and the querystring work.I get the value in my script. So now I only need to define the search. – J Net Jan 14 '18 at 22:08