Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

how to buid a URL for prefilling a field value for one record producer?

Raju Singh1
Tera Expert

how to buid a URL for prefilling a field value for one record producer.

I have one variable called 'user name' in record producer.

I have a URL for that record producer. As per my requirement whenever a new user is created in the system, it sends a notification which contains a URL to that record producer. Now when I click on this URL it should prepopulate a variable called user name with the a new user created.

Could you please help me achieving this requirement.

1 ACCEPTED SOLUTION

Goran WitchDoc
ServiceNow Employee

Well, you need to put in a parameter in the url to have the sys_id of the user.. like this, here I added sysparm_caller



https://devXXXXX.service-now.com/com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=66c313e...



Then you need a onLoad Catalog client script that puts that info into the variable.. in this case I'm putting it into a variable called "caller_id"



find_real_file.png


View solution in original post

11 REPLIES 11

Goran WitchDoc
ServiceNow Employee

Well, you need to put in a parameter in the url to have the sys_id of the user.. like this, here I added sysparm_caller



https://devXXXXX.service-now.com/com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=66c313e...



Then you need a onLoad Catalog client script that puts that info into the variable.. in this case I'm putting it into a variable called "caller_id"



find_real_file.png


Hi Goran,



Thank you for your reply..



In my case my sending a notification when a new user is created. So, I can't put a sys_id of the user as everytime notification is sent when a new user is created and when a person clicks on the link, it opens a record producer with a new sys_id value of the user.



So, I can I put a particular user's record Id there in my URL.


Is there a way which stores a sys id of the new user and that I could use in my URL.


I get that in your query you are storing the sys_id of the caller in the variable callerParm


What should be my URL .. in my case when everytime I have a new user created.. and I want to pass that new user sys_id value passed to my URL


Raju Singh1
Tera Expert

I only get the sys_id of the new user in the required field. Please find the code and the output the code on the form



Capture.JPG


function onLoad() {



var newHire = getParmVal('sysparm_user');


alert(newHire);


g_form.setValue('new_hire',newHire);


//var obj=gs.getUser(newHire);


//alert(obj);


// g_form.setValue('new_hire',obj.user_name);




getValu(newHire);


}




function getParmVal(name){


      var url = document.URL.parseQuery();


      if(url[name]){


              return decodeURI(url[name]);


      }


      else{


              return;


      }


}






function getValu(newHire){


var y = new GlideRecord(newHire);


      y.addQuery('sys_id',searchSys_id);


      y.addActiveQuery();


      y.query();


      while(y.next())


      {


              if(y.sys_id == newHire ) // NEED this double check or else log will spit out alot lot of rubbish  


              {


                    alert("we r good   "+ y.user_name);


              }


      }


   


}


   


function getParmVal(name) {


alert(name);


name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");


var regexS = "[\\?&]"+name+"=([^&#]*)";


var regex = new RegExp(regexS);


var results = regex.exec( window.location.href );


if(results == null){


return "";


}else{


return unescape(results[1]);




}


alert(results);



}




Here is the source code for URL



<p>New Hire Number: ${number}</p>


<p> </p>


<p><a title="Managers Checklist" href="https://mycompany.service-now.com/nav_to.do?uri=/com.glideapp.servicecatalog_cat_item_view.do%3Fv%3D...{sys_id}">Managers Checklist</a></p>