Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get value of variable

Matheus Rissi2
Tera Expert

Hello everyone,

 

Recently I'm having a lot of difficulty with the following question: I'm having to hide a form field,
But the validation must be done on top of the parent's variables.

 

But, not the form variables, but those that the user selects on the portal.

How can I do this?

The variable I have to hide (This is the Case Task)

MatheusRissi2_0-1683901264229.png


The variable I have to use as validation (This is the Case)

MatheusRissi2_1-1683901304478.png

 

Thanks in advance to everyone who can help me.

1 ACCEPTED SOLUTION

Mallidi Suma
Tera Guru

Hi @Matheus Rissi2 ,

 

Write one client script in the child table, send its parent reference to the Server Side using GlideAjax, and use "serversideObj.variables.field_name" to fetch the parent's variable value.

 

I took a similar kind of example, in my case parent table is Case and this case record is having a variable called priority.

And my child's table is incident. So whenever someone tries to create a child incident to the case then it will check its variable priority value and should display a field called Approver.

Below are my both Server and Client Side Scripts:-

 

Client Side Script:-

Created one OnLoad Client script on my Child Table (In my example it's Incident Table your's is Case Task Table)

function onLoad() {
//Type the appropriate comment here, and begin the script below
var parent_sysid = g_form.getValue('parent'); 
var ga = new GlideAjax('sendCaseVaribleInfo');
ga.addParam('sysparm_name','sendInfo');
ga.addParam('sysparm_parentSysId',parent_sysid);
ga.getXML(ResponseFunction);

function ResponseFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if(answer == 'yes')
{
g_form.setVisible('u_approver',true); // Instead of approver write your hidden field back end value
}
else
{
g_form.setVisible('u_approver',false);
}
}
}

 

Server Side Code:-

Created one client callable script include.

 

var sendCaseVaribleInfo = Class.create();
sendCaseVaribleInfo.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

sendInfo: function()
{
var CaseNumber = this.getParameter('sysparm_parentSysId');
var gr = new GlideRecord('sn_customerservice_case');
gr.addQuery('sys_id',CaseNumber);
gr.query();
if(gr.next())
{
if(gr.variables.priority == '4') // Afte variables.addYourVariableBackEndName and built the logic
{
return "yes";
}
else
{
return "no";
}
}
},
type: 'sendCaseVaribleInfo'
});

 

Please my answer as helpful if it helps!!

View solution in original post

1 REPLY 1

Mallidi Suma
Tera Guru

Hi @Matheus Rissi2 ,

 

Write one client script in the child table, send its parent reference to the Server Side using GlideAjax, and use "serversideObj.variables.field_name" to fetch the parent's variable value.

 

I took a similar kind of example, in my case parent table is Case and this case record is having a variable called priority.

And my child's table is incident. So whenever someone tries to create a child incident to the case then it will check its variable priority value and should display a field called Approver.

Below are my both Server and Client Side Scripts:-

 

Client Side Script:-

Created one OnLoad Client script on my Child Table (In my example it's Incident Table your's is Case Task Table)

function onLoad() {
//Type the appropriate comment here, and begin the script below
var parent_sysid = g_form.getValue('parent'); 
var ga = new GlideAjax('sendCaseVaribleInfo');
ga.addParam('sysparm_name','sendInfo');
ga.addParam('sysparm_parentSysId',parent_sysid);
ga.getXML(ResponseFunction);

function ResponseFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if(answer == 'yes')
{
g_form.setVisible('u_approver',true); // Instead of approver write your hidden field back end value
}
else
{
g_form.setVisible('u_approver',false);
}
}
}

 

Server Side Code:-

Created one client callable script include.

 

var sendCaseVaribleInfo = Class.create();
sendCaseVaribleInfo.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

sendInfo: function()
{
var CaseNumber = this.getParameter('sysparm_parentSysId');
var gr = new GlideRecord('sn_customerservice_case');
gr.addQuery('sys_id',CaseNumber);
gr.query();
if(gr.next())
{
if(gr.variables.priority == '4') // Afte variables.addYourVariableBackEndName and built the logic
{
return "yes";
}
else
{
return "no";
}
}
},
type: 'sendCaseVaribleInfo'
});

 

Please my answer as helpful if it helps!!