setting field values on a record from the script section in a record producer

patricklatella
Mega Sage

Hi all,

I've got a record producer that I've built to create records in a custom table extended from Task.   The records have some fields that I want to populate automatically when created by the record producer that pull values from the user record of the person submitting the record producer.

Having trouble with the script in the record producer to do this.

Can I simply dot walk into the users record?   Or do I have to set up a Gliderecord query?

example...one field on the form is "location", which is a field on the sys_user table.

thanks!

find_real_file.png

1 ACCEPTED SOLUTION

patricklatella
Mega Sage

it actually was simple enough to just do a GlideRecord, I did this script on the record producer and it works perfectly.



//Set the location and region on the generated record


user = gs.getUserID();


var userDetails = new GlideRecord('sys_user');//table where desired variable lives


userDetails.addQuery('sys_id',user);


userDetails.query();



if(userDetails.next())


{


current.location = userDetails.location;


current.region = userDetails.location.u_region;//name of field with info you want to grab


}


View solution in original post

9 REPLIES 9

Lakshmaiah Dump
Giga Expert

Hi



Hi Jim,



Create a viable with "Location" and choose the reference as variable type, Then select the reference table   is sys_user or your customized user table.


You can also use the depend value like if you the get the location of user x. It's simple pass the user viable in reference qual function as input.



javascript: getUserID(user_name);



If it simple location use the reference qual with dot working.


If you want do some complex processing use the script include with advances reference qual.



https://community.servicenow.com/message/1290355#1290355


Hit Like/Helpful as when felt


@Lakshmaiah


patricklatella
Mega Sage

something like this?   this is not working, but is this headed in the right direction?



var empLocation = g_form.getReference('location');//location is the field on the user record


current.location = empLocation;//location here is the field on the table


var grParent = new GlideRecord('parent table name');


if (grParent.get(g_form.getValue('parent'))) {


      //your logic goes here...


      g_form.setValue('opened_for', grParent.opened_for);    


      g_form.setValue('location', grParent.location);    


}


Hit Like/Helpful as when felt


@Lakshmaiah


patricklatella
Mega Sage

Hi Lakshmaiah,


thanks for the reply.   For the 'parent table name', do you mean the table I want to query to get the location of the user, (sys_user), or do you mean the table that record producer is going to put the record?



and for if (grParent.get(g_form.getValue('parent'))) {   , do I keep that line as is?   or do I put something where 'parent' is?