Passing parameters on different forms

gustavo1
Kilo Contributor

I want to pass a parameter on different forms, is it possible? i.e.
I have the form A where is located the field "user name", what I'm looking for is to extract that parameter and assign it to other field on the form B, which is inherent from A form.
Any idea or suggestion?, thanks in advance for your responses.

Regards.

6 REPLIES 6

gustavo1
Kilo Contributor

I'm taking as reference the links below:
Record Producer: Related Fields on another table
http://www.servicenowguru.com/scripting/client-scripts-scripting/parse-url-parameters-client-script/

But isn't clear to me yet! do I need an UI Action or something else? please help! I'm a newbie!


gustavo1
Kilo Contributor

Ok this is what so far I got:

- UI Action:
var parentTask = "&sysparm_parentTask=" + g_form.getUniqueValue();
var url = 'com.glideapp.pm_project.do?sys_id=' + parentTask + '&sysparm_comments=Finally it works!';

- Client Script:
function onLoad() {
var mycomms = getParmVal('sysparm_comments');
if(mycomms){
g_form.setValue('description',mycomms);
}
}

function getParmVal(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 results[1];
}
}

I still don't get to fetch the parameter "sysparm_comments", honestly I don't know what I'm doing wrong, please give me some guidance, I'm a desperate newbie!



Hey gustavo, I'm happy to help. Can you be a bit more specific about what, exactly isn't working? It looks like your UI action code isn't complete since it doesn't have any redirect command in it. Have you tried to print out the value of 'window.location.href' to see if things are being passed correctly? Try putting this in as the first line inside your 'onLoad' function to see if it contains the correct parameter. Then you would be able to see if the issue lies with the UI action or client script.

alert(window.location.href);

If you can set this up in one of the demo instances and let me know how to test it I can take a look.


gustavo1
Kilo Contributor

Hey Mark!

Actually I'm totally blind sailing! I mean I don't know if what I'm doing is ok, sadly I guess not.
I'm working on the PPM module, what I'm trying to do is, on a current project when somebody with right permissions creates a new task, automatically that task being assigned to the project manager assigned for that project.
So the way I figured out to get it was fetching the "sys_id" from the project, then on the "tasks" with a Client Script built a query, get the project manager name and assign it.
But as you realize I don't know anything about how to use the UI Actions or how passing variables or parameters into Service Now :S
So my question is, what do I need on the UI Action to redirect and populate the only field I need (which is sys_id)?

Thanks in advance for your response, I really appreciate your support.