The CreatorCon Call for Content is officially open! Get started here.

Call a property in script include which is called in Reference Qualifier

Nandini DM
Tera Contributor

Hi ,

I have a Script Include which sets the "group" field based on "type" field, however I am not supposed to use sys_id in script include and created system property for each sys_id which needs to be called in script include 

 

Below is the code which is working fine when sys_id is directly added to the script , here my question is how to add system property in place of sys_id in the below code?

 

var a = gs.getProperty(populate.group.based.on.type.finance);

 u_getGroupRefQual: function() {
        var filter = '';
        if (current.variables.do_you_need_access_to_finance_hr_or_it_applications.getDisplayValue() == 'Finance') {
            filter = 'active=true^type=747c67191b59ac500b457662164bcba4';
        }
        return filter;
    },
 
Please help me!
Thank you in advance!
1 ACCEPTED SOLUTION

M Ismail
Tera Guru

Hi @Nandini DM,

try this code 

u_getGroupRefQual: function() {
    var filter = '';
    var financeSysId = gs.getProperty('populate.group.based.on.type.finance');

    if (current.variables.do_you_need_access_to_finance_hr_or_it_applications.getDisplayValue() == 'Finance') {
        filter = 'active=true^type=' + financeSysId;
    }
    return filter;
},

Please hit helpfult and accept this as a solution if it solved your problem.
Thank you!

View solution in original post

13 REPLIES 13

Hi @M Ismail 
Spilt is not working , tried both

Hi @Nandini DM ,
If `split()` is not working as expected, it's possible that the system property value is not formatted correctly for splitting. Here are a few things to check and try:

1. **Ensure Correct Delimiter**:
- Make sure that the system property value is separated by the delimiter you're using for splitting (e.g., comma `,`).
- Check the actual value of the system property in the ServiceNow system properties table to confirm the delimiter used.

2. **Trim Whitespace**:
- If there is whitespace around the sys_ids or delimiter, it can affect the splitting. Trim the whitespace before splitting.


var financeSysIds = gs.getProperty('populate.group.based.on.type.finance').trim().split(',');
```

3. **Check for Empty Values**:
- If there are empty or null values in the system property, they can cause issues with splitting. Filter out empty values before using them.


var financeSysIds = gs.getProperty('populate.group.based.on.type.finance').split(',').filter(Boolean);
```

4. **Debugging**:
- Add logging statements to debug and see the actual value of the system property and the result of splitting.


var propertyValue = gs.getProperty('populate.group.based.on.type.finance');
gs.info('System Property Value: ' + propertyValue);
var financeSysIds = propertyValue.split(',');
gs.info('Split Result: ' + financeSysIds);
```

By checking these points, you should be able to identify why `split()` is not working as expected and adjust your code accordingly. 

Mark Manders
Mega Patron

I assume the 'type' you are referring to is the type listed in the sys_user_group_type-table? Why not query that table directly? 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

swathisarang98
Giga Sage

Hi @Nandini DM ,

 

If based on type you are populating group you can directly use reference qualifier for this no need to call script include, if your requirement is different please let me know what exactly you are trying to do.

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

Hi @swathisarang98 
Can you please help me with example?
Among 2 fields
If user selects x in type field , group field should populate all the x type groups in the look up field