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.

Display Info MSG on CHG request formwhen change tasks are active

praveen47
Tera Contributor

Hi All, 

 

I have a requirement change request have any active change tasks are presented in related list tab, need to display info message on Change form. 

 

I have written the below scripts, when checked using logs it is getting always return false.

Can some one help me on this.

Script Inlcude:

//  Display info message
	checkimpTask: function(parentChg) {
        var answer;
        var chgTask = new GlideRecord("change_task");
        chgTask.addQuery("change_request", parentChg);		
        chgTask.addQuery("change_task_type", "planning");
        chgTask.addQuery("active", "true");
        chgTask.query();
        if (chgTask.next()) {
			
            answer = 'true';
	} 
        return answer;
		
    },

 Client script:

Onload

table: change

function onLoad() {
    //Type appropriate comment here, and begin script below
    var cTask = new GlideAjax('StdChangeTaskUtils');
    cTask.addParam('sysparm_name', checkimpTask);
    cTask.getXML(chgTask);
}
function chgTask(response) {
    var Validation = response.responseXML.documentElement.getAttribute('answer');
    if (Validation == 'true') {
        g_form.showFieldMsg('Display comments');

    }
}

 

Thanks,

Praveen D.

 

2 ACCEPTED SOLUTIONS

Sandeep Rajput
Tera Patron
Tera Patron

@praveen47 Please update your script include as follows.

//  Display info message
	checkimpTask: function() {
        var answer;
        var parentChange = this.getParameter("sysparm_parent_change"); 
        var chgTask = new GlideRecord("change_task");
        chgTask.addQuery("change_request", parentChange);		
        chgTask.addQuery("change_task_type", "planning");
        chgTask.addQuery("active", "true");
        chgTask.query();
        if (chgTask.next()) {
			
            answer = 'true';
	} 
        return answer;
		
    },

Make sure that the script include has Client Callable checkbox checked.

 

Update the client script as follows.

function onLoad() {
    //Type appropriate comment here, and begin script below
    var cTask = new GlideAjax('StdChangeTaskUtils');
    cTask.addParam('sysparm_name', 'checkimpTask');
    cTask.addParam('sysparm_parent_change',g_form.getUniqueValue());
    cTask.getXML(chgTask);
}
function chgTask(response) {
    var Validation = response.responseXML.documentElement.getAttribute('answer');
    if (Validation == 'true') {
        g_form.showFieldMsg('Display comments');

    }
}

 

Hope this helps.

 

View solution in original post

piyushsain
Tera Guru

you did not send the Parent Change sys_id in OnLoad Client script, add the sys_id in parameter in Glide Ajax and retrieve the parameter in Client callable script Include

 

Script Include:

//  Display info message
	checkimpTask: function() {
        var parentChg = this.getParameter('sysparm_parentChange');
        var answer;
        var chgTask = new GlideRecord("change_task");
        chgTask.addQuery("change_request", parentChg);		
        chgTask.addQuery("change_task_type", "planning");
        chgTask.addQuery("active", "true");
        chgTask.query();
        if (chgTask.next()) {
			
            answer = 'true';
	} 
        return answer;
		
    },

 Client script:

Onload

table: change

function onLoad() {
    //Type appropriate comment here, and begin script below
    var cTask = new GlideAjax('StdChangeTaskUtils');
    cTask.addParam('sysparm_name', checkimpTask);
   cTask.addParam('sysparm_parentChange', g_form.getUniqueValue());
    cTask.getXML(chgTask);
}
function chgTask(response) {
    var Validation = response.responseXML.documentElement.getAttribute('answer');
    if (Validation == 'true') {
        g_form.showFieldMsg('Display comments');

    }
}
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

View solution in original post

5 REPLIES 5

Anand Kumar P
Giga Patron

HI @praveen47 ,

Use below script it will work

 

 

//Create new script include and make client callable true checkbox and paste below code
checkimpTask: function() {
        var answer = ''; 
var parentChg=this.getParameter('sysparm_parent_chg');
        var chgTask = new GlideRecord("change_task");
        chgTask.addQuery("change_request", parentChg);
        chgTask.addQuery("change_task_type", "planning");
        chgTask.addQuery("active", "true");
        chgTask.query();
        if (chgTask.next()) {
            answer = 'true';
        }
        return answer;
    },
});
function onLoad() {
    var parentChange = g_form.getValue('sys_id'); // parent change record's sys_id
    var cTask = new GlideAjax('StdChangeTaskUtils');
    cTask.addParam('sysparm_name', 'checkimpTask');
    cTask.addParam('sysparm_parent_chg', parentChange); 
    cTask.getXML(checkChangeTasks);
}

function checkChangeTasks(response) {
    var validation = response.responseXML.documentElement.getAttribute('answer');
    if (validation === 'true') {
        g_form.addInfoMessage('Active change tasks are present in the related list.');
    }
}

 

 

Please mark it as helpful and solution proposed if it works for you.

 

Thanks,

Anand