- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 02:24 AM - edited 01-03-2025 04:07 AM
Hello guys!
I have a problem regarding a specific Catalog Item's sc_task (SCTASK). Update: The workflow is based on sc_req_item table. This specific task has the following "Wait for condition" script in the workflow:
if (!gs.nil(current.project_resource)) {
// continue workflow
answer = true;
} else {
// wait until field project_resource is not empty
answer = false;
}
The Business Rule, based on sc_task table, is configured as follows:
- When: before
- Selected: Update + Insert
- Here is the following Business Rule script:
(function executeRule(current, previous /*null when async*/) {
// Kontrollera om det är en specifik catalog item
var catalogItemSysId = '0f0278598c2a1e10ebb6ef259418f246'; // catalog item Teknisk resursförfrågan.
if (current.cat_item == catalogItemSysId) {
// Kontrollera om state är satt till 3 (Avslutad)
if (current.state == 3) {
// Kontrollera om project_resource är ifyllt
if (gs.nil(current.project_resource)) {
gs.addErrorMessage('Du kan inte avsluta denna uppgift förrän "project_resource" är ifyllt.');
current.setAbortAction(true); // Stoppa uppdateringen
} else {
current.setAbortAction(false); // Tillåt uppdateringen
}
}
}
})(current, previous);
The problem: When I select a value for the project_resource field and I change the state of the SCTASK to 3 (Closed Complete) and save, I get the error message (that is only supposed to come when trying to close the SCTASK without a value in the project_resource field).
Update: the project_resource field is a custom field made for a specific catalog item.
Any ideas why? It is so frustrating and I just don't get why it is not working.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 03:25 AM
To clarify, this Business Rule is running on the sc_task table? 'project_resource' is not the name of an out of box field on the sc_task table. If you have added this field to the table, check the name. If this is a Catalog Item variable, then use:
if (gs.nil(current.variables.project_resource)) {
The same syntax would be used in the workflow script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 05:11 AM
Did you update the Wait for condition script?
if (!gs.nil(current.variables.project_resource)) {
// continue workflow
answer = true;
} else {
// wait until field project_resource is not empty
answer = false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 05:38 AM
@Brad Bowman yes mister! I've updated the Wait for and everything works now! 🙂 Thanks so much! 😍
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 05:23 AM - edited 01-03-2025 05:24 AM
so it's a variable based on which you need to wait.
So update the wait condition as per what Brad has mentioned.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 03:43 AM
what is project_resource field? where it is present?
What's your business requirement here?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 04:05 AM
I'm sorry.. the project_resource field is a custom made one for one specific catalog item only. That's where it is present.
The business requirement is for users in the back-end to need to fill in the project_resource (sys_user reference) in order to be able to close the sc_task created by the workflow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 04:08 AM
so it's a custom field on sc_task table?
Then it should be with name u_project_resource
Please share dictionary screenshot for that field for better understanding.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader