Script Include and OnLoad client script

Alon Grod
Tera Expert

Hi,

 

I have an onLoad client script on incident table that calls Script Include. The script include checks if login user is belong to some group, if he does he need to update the field u_record_changed to False. On the other hand, I need to write a BR on the incident table that every time a user make an update, the BR need to set u_record_changed to True. 

The problem is that in my script include im using 'inc.update()' in order to set the field to false and then because its an update the BR override the Script Include and set the field to True again, even though the goal is that it should stay on False. Any users that make update, the field should be set to True. If the login user belong to special group and he just load the incident without making any update then the field should be set to False.

var SetRecordChangedFalse = Class.create();

SetRecordChangedFalse.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    isHamal: function() {

        var std = this.getParameter('sysparm_std');
        var num = this.getParameter('sysparm_num');

        var standardFields = new GlideRecord('sys_user_grmember');
        standardFields.addQuery('user', std);
        standardFields.query();

        while (standardFields.next()) {

            var group_name = standardFields.group.toString();

            var gr = new GlideRecord('sys_user_group');
            gr.addEncodedQuery('sys_id=' + group_name + '^u_hamal=true');
            gr.query();
            if (gr.next()) {
                gs.log('ALon1');
                var inc = new GlideRecord('incident');
                inc.addEncodedQuery('sys_id=' + num);
                inc.query();
                if (inc.next()) {
						gs.log('Alon2');
                        inc.setValue('u_record_changed', false);
                        inc.update();
                }
            }
        }

    },
    type: 'SetRecordChangedFalse'
});

  

5 REPLIES 5

priyasunku
Kilo Sage

Hi @Alon Grod 

 

In Business rule you can add a condition saying Updated by is not system. This will avoid the override

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

 

 

@priyasunku hi, i made the BR in active in order to see what will be the value of updated by when the script include is making the update and the updated by is the login user and not the system.

@priyasunku so basically both the BR and the Script include will have the same value for updated by and i wont be able to distinguish between them

priyasunku
Kilo Sage

@Alon Grod In BR is it possible to check if loggedin user is part of a group again and set the field to true,

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful