current record value client script not on the g_form

mrswann
Kilo Guru

from the sc_task table, I have the following:

function onLoad(){

  var reqitem = g_form.getReference('request_item');

  //alert(reqitem.cat_item);

  if (reqitem.cat_item == ('hardcodedsysidpleasedontshootme') || reqitem.cat_item == ('ipromisetomovethistoasysproperty'))

  {

so I know from the Task, I can get the request_item as it is on the form and from that reference I can get the cat_item

But up a level, if I want to get the cat_item from the sc_req_item itself !! It is not present on the form so how I can access it?

Should I just add the item to the form?

1 ACCEPTED SOLUTION

ccajohnson
Kilo Sage

I have found that if a field is not available on the form it is not found using g_form methods. You could make the field available on the form, then create a UI Policy that hides it since it probably is not needed on the sc_req_item form. Then your g_form methods will work.



Let us know if you are still unsuccessful,


View solution in original post

6 REPLIES 6

Another solution to placing the field on the form and then hiding it with a UI action is to use g_scratchpad to pass the value from the server side to the client side. Then you know it's always available even if someone re-arranges the form layout later.



http://wiki.servicenow.com/index.php?title=Client_Script_Best_Practices#Example:_g_scratchpad


The thing I like about this is it is Best Practice and is somewhat future proof - thank you