how to restrict not moving to next state it should be in same state when my conditions not satisfy

Teja3
Tera Contributor

pls check below on change client script on problem table
when ever user select source as incident problem etc and under related list if no records associated then it should restrict not moving to assigned state and my code saving its moving to next state

 
// //Function to check associated records when state is in new
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var checks = g_form.getValue('state');
    g_form.addInfoMessage("check" + checks);
    if (checks == '1') //when state isnew
    {
        var ga = new GlideAjax('CheckAssociatedRecords1');
        ga.addParam('sysparm_name', 'checkAssocaited1');
        ga.addParam('sys_id', g_form.getUniqueValue());
        ga.addParam('source', g_form.getValue('u_source'));
        ga.getXML(removePending);
        // Prevent form submission
    }
}

function removePending(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");

    if (answer == 'true') {
        var source = g_form.getValue('u_source');
        if (source == '0') //source is IT Incident
        {
            g_form.addInfoMessage("Since the Source is selected as Incident, please associate Incident in the IT Incident list of the relevant tabs below");
        } else if (source == '1') //Source is Event
        {
            g_form.addInfoMessage("Since the Source is selected as Event, please associate alert in the Alerts list of the relevant tabs below");
        } else if (source == '4') // Source is IT Problem
        {
            g_form.addInfoMessage("Since the Source is selected as IT Problem, please associate problem  in the IT Problems list of the relevant tabs below");
        } else if (source == '8') //Source is IT Release
        {
            g_form.addInfoMessage("Since the Source is selected as IT Release, please associate release in the ITPPM RM Release list of the relevant tabs below");
            //alert("Since the Source is selected as IT Release, please associate release in the ITPPM RM Release list of the relevant tabs below");
        }
    }
    if(answer!='true'){
        g_form.setValue('state','1');
    }
}

below is script include

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

    checkAssocaited1: function() {
        var rec = this.getParameter('sys_id');
        var src=this.getParameter('source');



        if (src== '0') //when source is IT incident
        {
            var inc = new GlideRecord('itinc');
            inc.addQuery('problem', rec);
            inc.query();
            if (inc.getRowCount() < 1) {
                return true;
            }
            //it_problem

        } else if (src== '1') // when source is Event
        {
            var event = new GlideRecord('alert');
            event.addQuery('incident', rec);
            event.query();
            if (event.getRowCount() < 1) {
                return true;
            }
        } else if (src== '4') // when source is IT problem
        {
            var prb = new GlideRecord('problem');
            prb.addQuery('problem', rec);
            prb.query();
            if (prb.getRowCount() < 1) {
                return true;
            }
        } else if (src== '8') // When source is IT Release
        {
            var rel = new GlideRecord('ppm_rm_release');
            rel.addQuery('parent', rec);
            rel.query();
            if (rel.getRowCount() < 1) {
                return true;
            }

        }

    },

    type: 'CheckAssociatedRecords1'
});
7 REPLIES 7

As you mentioned, the condition requires the state is "new" and assigned to "changes," so your Business Rule will only execute when this condition is met. This means the BR will only run if the previous state is "new" and the assigned_to field changes to a different value.

so once you reload the form and try to save the form without changing assigned_to in that case BR won't execute because condition didn't match.

 

Hope this help you.

 

Regards

Moin

Teja3
Tera Contributor

it should restrict not moving to next state the next state is assigned so if assigned to any user then it will move to assigned state so i used assigned to changes 
how can i make it restrict

I'm still unclear about it. Could you please share a screenshot of the "When to run" section in the Business Rule?