- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 08:41 AM
Hi All,
Hopefully someone can help with the following. it sounds simple enough, but I can't get what I want to do to work.
What I need to happen is for a variable on a request task form to become mandatory on or before the 'Close Task' action. I have explored this via UI Policy and got it to work for it to be mandatory. However, the issue I have with that method is the task will need some work completing before variable information is acquired and you cannot save it as the field has already become mandatory.
The method I am now exploring is the onSubmit client script, but I am open to other options...
function onSubmit() {
var action = g_form.getActionName();
if (action != 'close_sc_task')
return;
var state = '3'; // Closed Complete State
if (action == 'close_sc_task');
g_form.setMandatory('business_email', true); // business email is the variable that need to become mandatory
}
What I have seen with the above script is that the business email variable flashes briefly with the mandatory asterisk, but the task closes anyway. Any help would be appreciated.
Many Thanks...
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 01:09 PM
I think I used the wrong syntax for the business rule. After Helsinki, they changed the syntax and no longer use onBefore() onAfter() methods. See if you can use this in your Set g_scratchpad for sc_task business rule:
(function executeRule(current, previous /*null when async*/) {
g_scratchpad.wf_activity = current.wf_activity.getDisplayValue();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 04:27 AM
Has Vasmi,
Thank you for your help, but no luck with this i'm afraid. The buiness email field doesn't even flash for a brief second to suggest it has become mandatory as it did before.
Kindest Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 04:48 AM
i observed a semi coloumn for if condition, i think you dont need it.
And can you check the return value for email and set corresponding condition in "IF". And added a "{ }"
and what is the field type for business_email ?
function onSubmit() {
var action = g_form.getActionName();
if (action != 'close_sc_task')
return;
var email = g_form.getvalue('business_email'); // reading the value
var state = '3'; // Closed Complete State
if (action == 'close_sc_task')
{
if(!email) // will work if email field is string,wont work if its a reference, you have to update condition to check undefined
{
g_form.setMandatory('business_email', true); // business email is the variable that need to become mandatory
return; // added return here so the task wont be closed
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 05:31 AM
it is a string field, i had tried having a return; at the end already and again i'm afraid it hasn't worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 09:43 PM
Sorry yesterday i just gave my thinking on the reply.
this is working and tested in my instance. nothing else to change. and I also found that this will not work if user right click on title pane and select save as the ui action then triggered will be 'sysverb_update_and_stay'. If you want that to be included then u can check if state is '3' as if (action == 'close_sc_task' && g_form.getvalue('state')=='3')
Updated Code
function onSubmit() {
var action = g_form.getActionName();
if (action != 'close_sc_task')
return;
var email = g_form.getValue('business_email'); // reading the value
if (action == 'close_sc_task')
{
if(email=='') // will work if email field is string,wont work if its a reference, you have to update condition to check undefined
{
g_form.setMandatory('business_email', true); // business email is the variable that need to become mandatory
g_form.setValue('state',2);
alert('please fill email');
return false; // added return here so the task wont be closed
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 12:18 AM
Did it work mohammed ? any luck with my code snippet?
