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

'parent table name' is generally sys_user. i.e Where you want to get the location with reference of user record.


grParent.get(g_form.getValue('parent') :: ;parent' means userid or name from sys_user table (Basically unique filed in the record).



Hit Correct/Endoresers/Like/Helpful as when felt


@Lakshmaiah



Lakshmaiah Dump
Giga Expert

User following call back method to get the location value using Catalog Client Scripts.



function onChange(control, oldValue, newValue, isLoading) {


    var caller = g_form.getReference('u_contact', getLocation);


    function getLocation(caller){


          //jslog("city::"+caller.city);


          if(caller.city){


              g_form.setValue("u_location", caller.city);


          }


    }


}



PS: Hit like, Helpful or Correct depending on the impact of the response .


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


}


how about using in this way,



var myUserObject = gs.getUser();


current.location = myUserObject.getLocation()



reference: http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0


hello Shishir,


thanks for the reply...I plugged your script in and it doesn't populate the "location" field on the record...is there more to it or should that work just like that?