- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 05:39 AM
Hi,
in project table i have a field called "it segment".if that i"t segment" is equal to "xyz" then only i need to set some values in child table(decision) like short description to "test"and approval required to yes
Please find the scripts used:
client script:table:Decission
function onLoad() {
//Type appropriate comment here, and begin script below
var itsegement=g_form.getValue("it_segments");------>it is in parent table
alert(itsegement);
var ga = new GlideAjax('SetValuesforITSDProject');-->my script include
ga.addParam('sysparm_name','myfunction');
ga.addParam('sysparm_user_name',g_form.getValue("it_segments"));
ga.getXML(setValue);
function setValue(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue("short_description",answer);
g_form.setValue("approval_required",'yes');
}}
script include:
var SetValuesforITSDProject = Class.create();
SetValuesforITSDProject.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
myfunction: function() {
var name = this.getParameter('sysparm_user_name').toString();
return "test";}
});
kindly help here. Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2018 02:17 AM
Hi Akash,
If you are having field on child which refers to parent then Have display business rule and set the value in scratchpad variable for it segment.
use this scratchpad variable in onLoad and compare it with your sys id and then set the value for the required fields.
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 07:09 AM
Hi David,
The above code is not working. And also when ever we click on new(child ticket), logic should get triggered, not only first time.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 07:28 AM
OK add in some debug messages:
function onLoad() {
alert(g_form.getValue("parent"));
var ga = new GlideAjax('SetValuesforITSDProject');-->my script include
ga.addParam('sysparm_name','myfunction');
ga.addParam('sysparm_parent',g_form.getValue("parent"));
ga.getXML(setValue);
function setValue(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue("short_description",answer);
g_form.setValue("approval_required",'yes');
}
}
var SetValuesforITSDProject = Class.create();
SetValuesforITSDProject.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
myfunction: function() {
var parent = this.getParameter('sysparm_parent');
gs.log(parent);
var gr = new GlideRecord('pm_project');
if(gr.get(parent)){
gs.log('script include got here and segment is: ' + gr.it_segments.getDisplayValue());
return gr.it_segments.getDisplayValue();
}
});
Confirm what is being returned in both alerts and both gs.logs
Also, check all table names and field names, the syntax should be correct but only you know the correct field and table names.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 07:47 AM
Hi David,
I am not getting any alerts or logs.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 07:52 AM
OK just realised, when you open a new decision form the parent field will be blank so it'll have nothing to go on. You'll need to run this onChange of the parent field, if the it segment is going to change on the parent form you'll need to have an after update business rule running on that to update child records when the value changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 07:58 AM
it is returning sys_id of project(parent)