- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2022 08:59 AM
Hi, I have an "item" table with an "item_description" translated text field. I want the value of this field to be updated whenever a field is changed, "cat_item" for example.
Since calculated value are not efficient, I want to calculate the value of this field with a business rule. I made a business rule that runs AFTER the "cat_item" field is updated and updates the item description.
My issue is that I want to update the english and the french value of the field, so I update the value of the field in english then create a translated text record for the french value, but since it uses the user's language, when I update the value it automatically updates the french translated text value instead of updating the actual value (if the user's language is french). I tried creating 2 translated text instead (one for english, one for french), but it doesn't work since the field needs to have a value.
Would it be possible to force the business rules to be run as system user (so that it would use the system's language instead and would always update the value in english?). I tried an async business rule but it's still being run by the user. What would be the best way to proceed in this case?
Thanks!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2022 11:02 AM
Hi Guillaume,
So yes there is a way to impersonate a system user through script. I think this community question explains it well.
https://community.servicenow.com/community?id=community_question&sys_id=be41cfe5db98dbc01dcaf3231f9619f2
That said have you tried running your insert with the following glide function : gliderecord.setWorkflow(false)
Once you place it in your code before the update or insert query, this will make sure that none of the Business rule written on your table will run.
This may ensure that your language doesn't automatically get updated after insert - but it would be wise to test this thoroughly if this option does work , as then this script would have no auditing to it.
Hope that helps.
Please mark my answer correct and helpful if this resolves your issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2022 11:02 AM
Hi Guillaume,
So yes there is a way to impersonate a system user through script. I think this community question explains it well.
https://community.servicenow.com/community?id=community_question&sys_id=be41cfe5db98dbc01dcaf3231f9619f2
That said have you tried running your insert with the following glide function : gliderecord.setWorkflow(false)
Once you place it in your code before the update or insert query, this will make sure that none of the Business rule written on your table will run.
This may ensure that your language doesn't automatically get updated after insert - but it would be wise to test this thoroughly if this option does work , as then this script would have no auditing to it.
Hope that helps.
Please mark my answer correct and helpful if this resolves your issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2022 06:27 AM
Hi Sean,
I didn't think of trying setWorkflow(false) and it worked! I knew you could impersonate by script but I figured you needed to have the impersonator role and that it was not really a good idea to allow anyone to impersonate System Administrator. I though that async business rules were run as system like flows for some reason, or that there was a way to force them to be run by system, but your solution works so it's good enough.
Thanks a lot !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2022 08:22 AM
Hi Guillaume,
That's great to hear, so glad it worked !
Happy coding 🙂