Getting the SysID

asher14
Tera Contributor

I am working on a onLoad Client script. I need help passing in the sysid value. Currently I have is passed in directly but because different evnironments have different sysid that will be a issue. How can I get the sysid of this value with code, rather than passing it directly in.

 

Here is what I have so far:

function onLoad(){

      if(g_form.isNewRecord(){

                g_form.setValue('u_category', sysid numbers);

         };

}

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

To get the sys_id of the current record, try

g_form.getUniqueValue()
This works onLoad for new and existing records, so as used in your script in the setValue function, this would set the value of your category field to the sys_id of the record, if that's really what you want to do.

AshishKM
Kilo Patron
Kilo Patron

Hi @asher14 ,

You can use the "g_form.getUniqueValue()" in place of "sysid numbers" suggested by @Brad Bowman  , if you are looking for sys_id of record which is not saved yet , this onLoad will not work for saved record. 

 

Query -> are you adding record's sys_id in category field, is it text field or mapped to Choice[sys_choice] table.

 

function onLoad(){
      if(g_form.isNewRecord(){
                g_form.setValue('u_category', g_form.getUniqueValue());
         };
}

-Thanks,

AshishKMishra

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution