Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get the Parameters from URL

Kusuma2
Kilo Guru

Hi Gurus,

I have a requirement to populate the field on the record producer when a record producer is created from incident.

UI page Client redirecting to Record Producer on selection:

 

Its working fine.

Now I want to get the sys_id present in the url to Record Producer Reference Field.

I have written the business Rule(before/after insert)  to get the parameter value from the url  and update the field but it showing me undefined.

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var cat = gs.action.getGlideURI().getMap().get('u_catalog_item');
gs.addInfoMessage(cat);

//var cat1 =gs.action.getGlideURI().indexOf('sysparm_u_catalog_item');
var cat2=RP.getParameterValue('sysparm_u_catalog_item');
//gs.addInfoMessage(cat1);
gs.addInfoMessage(cat2);
if(current.isNewRecord()){
gs.addInfoMessage("its is new record");
//current.u_incident=cat;
current.u_incident=cat1;
// current.u_incident=cat.getDisplayValue;
// current.u_incident=cat1.getDisplayValue;
//current.short_description= cat;
current.short_description= cat1;
current.update();
// g_form.setValue('u_incident', cat.toString());

}

})(current, previous);

 

 

 

11 REPLIES 11

Aj,

Your script is working as expected. The u_incident is a reference field. If you want to show the display value, you should pass it as a second parameter in your url.

function onLoad() {
  var cat2Label = getParmVal('sysparm_u_catalog_item_label');
  var cat2ID = getParmVal('sysparm_u_catalog_item_id');
  if(g_form.isNewRecord()){
     g_form.setValue('short_description', cat2Label);
     g_form.setValue('u_incident', cat2ID, cat2Label);
  }
 
 
   function getParmVal(name) {
     var url = document.URL.parseQuery();
     if(url[name]){
        return decodeURI(url[name]);
     } else {
        return;
     }
   }
}

Thanks for help again.I am new to scripting Could you please help me where can I make change.Inorder to pass the second parameter in the url.

find_real_file.png

Aj,

Reading you client script, I don't really understand what you are trying to do.

Let me know if I got it right.

  • A user is looking at an incident
  • He clicks on a button (?) to open a dialog box
  • In this box, he can choose to open a new incident
  • The incident record producer is opened and the original incident is referenced in the u_incident field

It feels like you're mixing up the sys id of the record producer you're trying to use and the current incident id.

 

 

 

Yes You got it.

a New dialog box opens on incident form and in that box I have a choice list field with choices(Record producer, CATALOG ITEM).

Based upon the selection it is redirecting. After getting redirected I would like to copy the incident number on the new Redirect form field(on record producer custom field).

How can I achieve this..is my approach not correctto solution not correct?

There is a problem with how you are trying to achieve this. What you are doing right now is opening a new Record producer record and initializing some fields.

What you want is using a record producer to initialize the creation of a new incident (right?).

You first need to know which record producer you have to open. Open this list to see the record producers that can produce an incident: /sc_cat_item_producer_list.do?sysparm_query=table_name%3Dincident&sysparm_list_mode=grid

The url you will open then is not directly on sc_cat_item_producer but rather /com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=3f1dd0320a0a0b99000a53f7604a2ef9 (for example for "Create Incident").

If you want to add fields to this record producer, you're going to add variables, just like you do with a catalog item.