Script Include with indexOf method

Annette Kitzmil
Tera Guru

Hello,

 

Below is a script include that when it gets to the section that is this color, it doesn't pick up the var backDating part that is part of the correction part of the function.  I can get a gs.addInfoMessage just inside of that part of the function, but I can't get a gs.addInfoMessage just past that part of the function, therefore, the conditions are skipped over.  What do I need to change here please so that it is picking up the var backDating.

 


    canViewConfirmButton: function() {

        var isMemberAccountService = gs.hasRole('x_mtbr_ebs_rdep.account_services');
        var isOpenedBy = gs.getUserID() == current.getValue('opened_by');

        var isOpenAccount = current.open_account == true;

        var existingCustomer = current.type_of_customer == 'existing customer';
        var prospectCustomer = current.type_of_customer == 'prospect customer';

        var statusPtApproved = current.status == 'pt_approved';
        var statusConfirmed = current.status == 'confirmed';
        var statusCorSupportApproved = current.status == 'cor_support_approved';

        if (this.requestType == 'correction') {
            //Correction Logic

            // var ct = current.type_of_correction_requested;
            // ct = ct.split(',');

            // var backDating = ct.indexOf(gs.getProperty('x_mtbr_ebs_rdep.redp.backdating_request')) >= 0;

            if (statusPtApproved || statusCorSupportApproved || statusConfirmed) {

                //This is for the Opened by user to confirm when Open Account is true and either PT Approved or Cor Support Approved
                if (isOpenAccount && isOpenedBy) {
                    return true;
                }

                //This is for Account Services when backDating and is either PT Approved or Cor Support Approved
                if (isMemberAccountService && backDating) {
                    return true;

                }

                //This is for an Opened by User Confirmed case with Open Account and includes backDating that Account Services is now Confirming so it routes to WNS
                if (isMemberAccountService && isOpenAccount && backDating) {
                    return true;
                }
            }

        } else {
            //Exception Logic

            if (statusPtApproved && existingCustomer && isOpenAccount && isOpenedBy) {
                return true;
            }

            if (statusPtApproved && prospectCustomer && isOpenedBy) {
                return true;
            }
        }

        return false;


    },

 

Thank you ahead of time for any help on this script.

 

1 ACCEPTED SOLUTION

OK, so ct is some comma-separated value, and the system property contains a value to search for. 

I'm going to assume that's like ct = sys_id1,sys_id2,sysid3.., and the Value of the system property is one of those sys_ids.  Let me know if this is not remotely close.

You can use indexOf in an array or string, but if all you are trying to determine is if the sys_id that is the Value of the system property appears anywhere in the field value, you don't need an array, so leave that out.  With the logs of ct and the system property still there as a sanity check, if you add back in the backDating line then log that variable right after, what do you get?

One thing you should do that shouldn't matter but can't hurt is force the values to a string, since they contain sys_ids.  Stranger things have worked.  And maybe get ridiculous with breaking this apart and logging to see if that sheds any light:

var ct = current.type_of_correction_requested.toString();
gs.info ('AK ct= ' + ct);
var sysprop = gs.getProperty('x_mtbr_ebs_rdep.redp.backdating_request').toString();
gs.info ('AK sysprop= ' + sysprop);
var backDating = ct.indexOf(sysprop) >= 0;
gs.info ('AK backDating= ' + backDating);

 

View solution in original post

7 REPLIES 7

The more I've thought about this, it makes sense that your original script stopped working in the ct area as the typeof the ct variable is likely not a string and you are attempting string functions with the split and indexOf.  If you just force ct to a string it should work, but maybe the system property needs the same since it's probably a string value of a sys_id, it might get interpreted differently when retrieved.

var ct = current.type_of_correction_requested.toString();

Hi Brad,

Your solution helped me arrive at the final solution to get this to work as expected.  I greatly appreciate your help.

Thanks

Gabriel MF
ServiceNow Employee
ServiceNow Employee

The logic is correct, you can search for the string both in full string and in the array. As @Brad Bowman  suggested try to debug both the array ct that you created with the 'split' and the property 'x_mtbr_ebs_rdep.redp.backdating_request' with gs.info() to make sure they have values as expected.