- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 07:23 PM
Hi,
We have a requirement that when user clicks in the new button of the related list “Project Change Requests” of the “Project” form:
The values from the “Project manager” field and “Sponsor” (custom) field of the “Project” form:
Goes to the 2 custom fields “Project Manager” and “Sponsor” of the “Project Change Request” form:
Can anyone help us to achieve this please?
Thanks and best regards,
Paulo
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 10:20 PM
Hi pauloferreira,
If you only want values from the “Project manager” field and “Sponsor” (custom) field of the “Project” form should go to the 2 custom fields “Project Manager” and “Sponsor” of the “Project Change Request” form only when user clicks on New button in related list on "Project" table then you can use the Display Business rule and onLoad client script as shown below:
Display BR on "Project Change Request" table:
(function executeRule(current, previous /*null when async*/) {
g_scratchpad.projectManager= current.parent.project_manager; // use Parent and Project Manager field name of "Project Change Request" table
g_scratchpad.sponsor= current.parent.sponsor;// use Parent and Sponsor field name of "Project Change Request" table
gs.info("projectManager : " + g_scratchpad.projectManager);
gs.info("sponsor: " + g_scratchpad.sponsor);
})(current, previous);
onLoad Client Script on "Project Change Request" table:
function onLoad() {
if(!g_form.getValue('project_manager')) // use Project Manager field name of "Project Change Request" table
g_form.setValue('project_manager', g_scratchpad.projectManager);
if(!g_form.getValue('sponsor')) // use sponsor field name of "Project Change Request" table
g_form.setValue('sponsor', g_scratchpad.sponsor);
}
Please let me know if you face any issue in this.
Please mark it correct, if it resolves your problem.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 07:35 PM
Hello Paulo,
You can do this via Client Script + GlideAjax approach. Please refer below link for more info and let me know if you have any questions.
https://community.servicenow.com/community?id=community_blog&sys_id=f8ccee25dbd0dbc01dcaf3231f961978
https://developer.servicenow.com/app.do#!/lp/servicenow_administrator/app_store_learnv2_scripting_istanbul_glideajax?v=istanbul
Thanks,
Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 10:20 PM
Hi pauloferreira,
If you only want values from the “Project manager” field and “Sponsor” (custom) field of the “Project” form should go to the 2 custom fields “Project Manager” and “Sponsor” of the “Project Change Request” form only when user clicks on New button in related list on "Project" table then you can use the Display Business rule and onLoad client script as shown below:
Display BR on "Project Change Request" table:
(function executeRule(current, previous /*null when async*/) {
g_scratchpad.projectManager= current.parent.project_manager; // use Parent and Project Manager field name of "Project Change Request" table
g_scratchpad.sponsor= current.parent.sponsor;// use Parent and Sponsor field name of "Project Change Request" table
gs.info("projectManager : " + g_scratchpad.projectManager);
gs.info("sponsor: " + g_scratchpad.sponsor);
})(current, previous);
onLoad Client Script on "Project Change Request" table:
function onLoad() {
if(!g_form.getValue('project_manager')) // use Project Manager field name of "Project Change Request" table
g_form.setValue('project_manager', g_scratchpad.projectManager);
if(!g_form.getValue('sponsor')) // use sponsor field name of "Project Change Request" table
g_form.setValue('sponsor', g_scratchpad.sponsor);
}
Please let me know if you face any issue in this.
Please mark it correct, if it resolves your problem.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2018 05:27 AM
Thank you very much for the reply, Pradep and Mahi.
Mahi,
Your suggestion worked fine just for the "Sponsor" field...the "Project Manager" field didn't receive the value from Project form:
I am sending the name of the fields of each table for your verification:
"pm_project" table (Project):
Field: project_manager Type Reference sys_user
Field: u_sponsor Type Reference sys_user
"project_change_request" table (Project Change Request):
Field: u_project_manager Type Reference sys_user
Field: u_sponsor Type Reference sys_user
I'm using the following scripts:
Display BR on "Project Change Request" table:
(function executeRule(current, previous /*null when async*/) {
g_scratchpad.projectManager= current.parent.u_project_manager; // use Parent and Project Manager field name of "Project Change Request" table
g_scratchpad.sponsor= current.parent.u_sponsor; // use Parent and Sponsor field name of "Project Change Request" table
gs.info("projectManager : " + g_scratchpad.projectManager);
gs.info("sponsor: " + g_scratchpad.sponsor);
})(current, previous);
onLoad Client Script on "Project Change Request" table:
function onLoad() {
if(!g_form.getValue('u_project_manager'))
g_form.setValue('u_project_manager', g_scratchpad.projectManager);
if(!g_form.getValue('u_sponsor'))
g_form.setValue('u_sponsor', g_scratchpad.sponsor);
}
Thanks and best regards,
Paulo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2018 05:36 AM
Hi Mahi,
We did the following change in the BR script (in bold below):
Display BR on "Project Change Request" table:
(function executeRule(current, previous /*null when async*/) {
g_scratchpad.projectManager= current.parent.project_manager; // use Parent and Project Manager field name of "Project Change Request" table
g_scratchpad.sponsor= current.parent.u_sponsor; // use Parent and Sponsor field name of "Project Change Request" table
gs.info("projectManager : " + g_scratchpad.projectManager);
gs.info("sponsor: " + g_scratchpad.sponsor);
})(current, previous);
Instead using the project manager field name of the project change request form...we used the project manager field name of the project form.
For sponsor field it worked before because both fields have the same name (u_sponsor).
Thank you very much for your help.
Best regards,
Paulo