How to validate if atleast one child record exists in UI action

vijay23
Tera Contributor

Hi . 

 

 i have a requirement .

to create a UI action - "Monitoring" in problem table

when click on the button , it should check if at least one child task(action table) related to problem record exists.

if not exists, it should throw an error message - "at least one action record needs to be created to move to monitoring"

all these should execute on client side .

because in sever side if we execute , state value will move to "monitoring" and error message will be displayed and after refreshing it will move back to previous state, so we need to avoid this confusion to users 

also the same requirement should work in service operation workspace .

 

Can anyone please suggest how to build the code "GLideajax call" and validate if at least one action related to problem exists and should execute this in client side?

 

1 ACCEPTED SOLUTION

seethapathy
Giga Guru
HI @vijay23  I tried your requirement in PDI And found this Logic is Working. if this helpful mark it as helpful.
 
UI Action logic
function monitoring(){
var pbid =g_form.getUniqueValue();
var ga = new GlideAjax("Your Script Include Name");
ga.addParam("sysparm_name""Your Script include Function Name");
ga.addParam("sysparm_id",pbid);
ga.getXML(testing);
function testing(response){
    var sp =response.responseXML.documentElement.getAttribute("answer");
        if(sp== true){
g_form.setValue('state','monitoring');
    }
    else{
        g_form.addErrorMessage("at least one action record needs to be created to move to monitoring");
    }
   
}}
 
Script Include 
    checkTask: function() {
        var sysid=this.getParameter('sysparm_id');
         var gr = new GlideRecord('Your child Table Name');
        gr.addQuery('problem',sysid);
        gr.query();
        if (gr.hasNext()) {
            return 'true';
        }
        else {
            return 'false';
        }

    }

View solution in original post

8 REPLIES 8

Hi,

How to execute the same behaviour in Workspace as well

what script do I need to configure in workspace client script? can you help?

seethapathy
Giga Guru
HI @vijay23  I tried your requirement in PDI And found this Logic is Working. if this helpful mark it as helpful.
 
UI Action logic
function monitoring(){
var pbid =g_form.getUniqueValue();
var ga = new GlideAjax("Your Script Include Name");
ga.addParam("sysparm_name""Your Script include Function Name");
ga.addParam("sysparm_id",pbid);
ga.getXML(testing);
function testing(response){
    var sp =response.responseXML.documentElement.getAttribute("answer");
        if(sp== true){
g_form.setValue('state','monitoring');
    }
    else{
        g_form.addErrorMessage("at least one action record needs to be created to move to monitoring");
    }
   
}}
 
Script Include 
    checkTask: function() {
        var sysid=this.getParameter('sysparm_id');
         var gr = new GlideRecord('Your child Table Name');
        gr.addQuery('problem',sysid);
        gr.query();
        if (gr.hasNext()) {
            return 'true';
        }
        else {
            return 'false';
        }

    }

Hi,

 

How to execute the same behaviour in Workspace as well?

what script do I need to configure in workspace client script? can you help?

Hi @seethapathy ,

 

this is working as expected in backend, but how to make this to work in service operation workspace? do you have any idea?