- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 02:42 AM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 02:48 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 07:48 AM
Hi @M Ismail
Spilt is not working , tried both
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 08:08 AM - edited 03-12-2024 08:09 AM
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 as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 02:51 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 02:54 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 03:00 AM
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