I want to display pending reason custom filed on sc_task table based on state choices?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2019 12:16 AM
I had created one custom filed called "pending reason" on sc_task table
As a requester fulfiller, I should be able to navigate through requested item >> Catalog Task
Make sure that the catalog Task is either in Open or Work in Progress state. Move the Task to Pending State
System should provide field - Pending Reason and will be required field for state = Pending
Pending Reason should have following three option to Select
-
- Awaiting Requester
- Awaiting Change
- Awaiting Vendor
I have created below onChnage client script it works for state filed on change but after loading getting wrong results
How can I get oldValue & newValue of state choices on load client script?
/**
states are 1 - open
2- work-in progess
3- closed complete
4- closed incomplete
-5 - pending
7 - closed skipped
**/
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if ((oldValue == "1" && newValue == "-5") || (oldValue == "2" && newValue == "-5")) {
g_form.setDisplay("u_pending_reason", true);
alert("state are 1 2 -5 onchange if loop");
} else if ((oldValue == "4" && newValue == "-5") || (oldValue == "3" && newValue == "-5") || (oldValue == "7" && newValue == "-5")) {
g_form.setDisplay("u_pending_reason", false);
alert("state are 3 4 7 -5 onchange else if loop");
}
else{ g_form.setDisplay("u_pending_reason", false);}
}
Initially I have to hide pending reason filed onload then
if I change the state changes from open to pending or Work in progress to pending
I have to show "pending reason" field
Rest all scenarios like state changes from closed complete to pending or closed incomplete to pending or closed skipped to pending
I don't want to show pending reason filed
If I created UI policy when task is created by default it is "open" state so pending reason is filed visible directly but my use case is when state changes from open to pending or Work in progress to pending
I have to show "pending reason" field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2019 01:19 AM
HI,
First of all, the task once closed or skipped should not be editable.
Second if you dont have on load checkbox as true on UI policy it will not hide it.
Third if your condition's are good in UI policy then it should work.
UI policy action is simple:
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2019 09:08 AM
I have written same UI policy as it is but the problem is whenever I changed to pending state Pending reason filed is visible for all scenarios as below
1.state changes from open to pending or Work in progress to pending
Pending reason field is visible
2. state changes from closed complete to pending or
closed incomplete to pending or
closed skipped to pending
Pending reason field is visible
But my use case is only first point to be enable Pending reason field is visible, I dont want to be visible on the 2nd point, How can I achieve this with UI policy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2019 09:25 AM
You can not achieve your 2nd point with UI Policy. Client script can only help you here.
Can you try this client script and see if it works for you?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
g_form.setDisplay("u_pending_reason", false);
return;
}
if ((oldValue == "1" && newValue == "-5") || (oldValue == "2" && newValue == "-5")) {
g_form.setDisplay("u_pending_reason", true);
alert("state are 1 2 -5 onchange if loop");
} else if ((oldValue == "4" && newValue == "-5") || (oldValue == "3" && newValue == "-5") || (oldValue == "7" && newValue == "-5")) {
g_form.setDisplay("u_pending_reason", false);
alert("state are 3 4 7 -5 onchange else if loop");
}
else
{
g_form.setDisplay("u_pending_reason", false);
}
}
//Type appropriate comment here, and begin script below

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2019 12:03 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2019 01:37 AM
As Ashutosh said - Once the task is marked closed complete/incomplete, State should be made read-only.
Reason being - Catalog Tasks are processed with the workflow, and workflow generally stops once tasks are closed.