How to set field value in existing record using Navigation URL?

michelhanna
Kilo Guru

Hi,

I need to construct a navigation URL, which will act as a callback URL to servicenow from a 3rd party system. The URL will open an existing record in one of the tables and set a value in a specific field..

I've the following URL where I open an existing record by sys_id, then passing a value to the target field, but didn't work:

https://<baseURL>.service-now.com/nav_to.do?uri=<table name>.do?sys_id=<sys_id_for_target_record>%26sysparm_query=target_field=xyz

Is that something doable?

Thanks,

Michel

1 ACCEPTED SOLUTION

paulmorris
Giga Sage

Unfortunately that API only works for new records


If you want to set specific values on load for existing records you'll need to use a Client Script or Display Business Rule.



You could be tricky and put a useless parameter in the URL, then use an onLoad client script to parse the URL and set the values if required.



example URL


incident.do?sys_id=8f632fea6f560200884750be5d3ee462&parm1=test




function onLoad() {


    //Type appropriate comment here, and begin script below


      if (top.window.location.href.indexOf("parm1=test") > -1 ) {


  g_form.setValue('short_description','Redirected from URL');


  }


}



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

3 REPLIES 3

paulmorris
Giga Sage

Unfortunately that API only works for new records


If you want to set specific values on load for existing records you'll need to use a Client Script or Display Business Rule.



You could be tricky and put a useless parameter in the URL, then use an onLoad client script to parse the URL and set the values if required.



example URL


incident.do?sys_id=8f632fea6f560200884750be5d3ee462&parm1=test




function onLoad() {


    //Type appropriate comment here, and begin script below


      if (top.window.location.href.indexOf("parm1=test") > -1 ) {


  g_form.setValue('short_description','Redirected from URL');


  }


}



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Excellent work around! I've tried it and I was able to capture the sent value which in your example = 'test'.


Thanks.


The example HTML is obtained by looking at the current browser window.

I have a slightly different example:

In my case, I open a webpage from within the main ServiceNow frame (the navbar and servicenow header are still there).  I click on a link on the webpage and it will send it back to the incident ticket where I want to do the same thing with regards to processing the URL and having a parameter.

top.window.location.href is incorrect because it's still looking at the main servicenow link, so how do I look at the current frame instead?