Not entering while Loop for getting models for a user

venugopal s
Tera Contributor

Hi everyone, 

I have written a script, where I need to get all models for certain user when the Extend to Order for Others is true. I am getting exact values through background script, but in main script its not entering while loop.

    if (device_function == 'primary_new_hire') {
            if (!grpmember) {
                var grEntitlement = new GlideRecord('u_m2m_sys_user_model_entitle');
                grEntitlement.addQuery('sys_user', orderby);
                gs.info('testing order By  ' + orderby);
                grEntitlement.query();
                gs.info('testing after query');
                while(grEntitlement.next()) {
                    gs.info('testing in while ' + grEntitlement.u_model_entitlement_exceptions);
                    if (grEntitlement.u_extend_to_order_for_others == true) {
                       var entitleModelId = grEntitlement.u_model_entitlement_exceptions.u_display_name;
                        gs.info('testing if after while' + entitleModelId);
                    }
                }
            }
        }
 Thanks
venugopals_0-1716364416653.png

 

venugopals_0-1716364511481.png

 

@Ankur Bawiskar  @Sandeep Rajput 

4 REPLIES 4

Community Alums
Not applicable

Hi @venugopal s 

Check whether the Order By field is having the sys_id of the user. While getting the sys_id try to use orderby.toString(). It is recommended to use toString() function whenever you are dealing with "Sys_id's" Let me know if you have any questions.

 

Regards,

Lithesh

Ankur Bawiskar
Tera Patron
Tera Patron

@venugopal s 

please share the complete script and how are you invoking?

seems some issue with field name and value in query

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

@Ankur Bawiskar ,
I modified script and getting value for entitleModelId, not able to show in the payload. Thanks

@venugopal s 

sorry but without the relevant script and screenshots we can't help

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