attach problem to change related list and vise versa

RamuN
Tera Contributor

Hi Team

To implement above requirement i have created 2 before business rule and one script include 

the below code is working when we add only one problem or one change to problem or change related list but if we add two or multiple at a time by selecting check box from problem/change related list then this code is not executing as expected

var SyncChangeProblem = Class.create();

SyncChangeProblem.prototype = {

    initialize: function() {},

 

    syncFromChangeRequest: function(changeGr, oldParentId) {

        var problemId = changeGr.parent;

        if (!problemId && oldParentId) {

            var oldProblem = new GlideRecord('problem');

            if (oldProblem.get(oldParentId)) {

                oldProblem.setValue('rfc', '');

                oldProblem.autoSysFields(false);

                oldProblem.update();

            }

            return;

        }

 

        var problemGr = new GlideRecord('problem');

        if (problemGr.get(problemId)) {

            problemGr.setValue('rfc', changeGr.sys_id);

            problemGr.autoSysFields(false);

            problemGr.update();

        }

 

    },

 

 

    syncFromProblem: function(problemG, oldchgreqId) {

 

        var changeId = problemG.rfc;

        if (!changeId && oldchgreqId) {

 

            var oldChange = new GlideRecord('change_request');

            if (oldChange.get(oldchgreqId)) {

                oldChange.setValue('parent', '');

                oldChange.autoSysFields(false);

                oldChange.update();

            }

            return;

        }

 

        var changeGr = new GlideRecord('change_request');

        if (changeGr.get(changeId)) {

            changeGr.setValue('parent', problemG.sys_id);

            changeGr.autoSysFields(false);

            changeGr.update();

        }

    },

 

    type: 'SyncChangeProblem'

};

 


Please suggest

8 REPLIES 8

Hi @Ankur Bawiskar 

thanks for the responce

 

please find below details

    var sync = new SyncChangeProblem();
    sync.syncFromProblem(current, previous.rfc.toString());


pbtochg1.png

 var sync = new SyncChangeProblem();
    sync.syncFromChangeRequest(current, previous.parent.toString());

 

chgtopb.jpg

@RamuN 

both the business rules should be after update and not Before update.

Also which business rule is not working?

did you debug by adding gs.info()?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

changed to after BR but still facing same issue

and two business rule triggering 2 times 

@RamuN 

try to use setWorkflow(false) just before the update in both the business rules

something like this

var SyncChangeProblem = Class.create();

SyncChangeProblem.prototype = {

    initialize: function() {},



    syncFromChangeRequest: function(changeGr, oldParentId) {

        var problemId = changeGr.parent;

        if (!problemId && oldParentId) {

            var oldProblem = new GlideRecord('problem');

            if (oldProblem.get(oldParentId)) {

                oldProblem.setValue('rfc', '');

                oldProblem.autoSysFields(false);
                oldProblem.setWorkflow(false);
                oldProblem.update();

            }

            return;

        }



        var problemGr = new GlideRecord('problem');

        if (problemGr.get(problemId)) {

            problemGr.setValue('rfc', changeGr.sys_id);

            problemGr.autoSysFields(false);
            problemGr.setWorkflow(false);
            problemGr.update();

        }



    },





    syncFromProblem: function(problemG, oldchgreqId) {



        var changeId = problemG.rfc;

        if (!changeId && oldchgreqId) {



            var oldChange = new GlideRecord('change_request');

            if (oldChange.get(oldchgreqId)) {

                oldChange.setValue('parent', '');

                oldChange.autoSysFields(false);
                oldChange.setWorkflow(false);

                oldChange.update();

            }

            return;

        }



        var changeGr = new GlideRecord('change_request');

        if (changeGr.get(changeId)) {

            changeGr.setValue('parent', problemG.sys_id);

            changeGr.autoSysFields(false);
            changeGr.setWorkflow(false);

            changeGr.update();

        }

    },



    type: 'SyncChangeProblem'

};

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader