
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2015 06:59 AM
Hi there is a UI action for the Close Task button, the script is set to mark the task Closed Complete upon clicking that button, but I want the task to mark based on the state; therefore IF the state = Closed Complete then when you click the Close Task button the functionality should mark the task as Closed Complete and IF the state = Closed Incomplete then when the Close task button is clicked the functionality should mark the task as Closed Incomplete.
I am having some difficulty in making that happen.
function closeTask(){
if(g_form.getValue('assigned_to') == '') {
//Remove any existing field message, set comments mandatory, and show a new field message
g_form.setMandatory('assigned_to', true);
g_form.showFieldMsg('assigned_to','Assigned to is mandatory when closing the task.','error');
return false; //Abort submission
}
g_form.setValue('state', '3');
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'close_Task'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
serverReopen();
function serverReopen(){
//Set the 'State' to 'Active', update and reload the record
current.update();
action.setRedirectURL(current);
}
Thanks,
Karen
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2015 09:59 AM
You should be able to say:
function closeTask(){
var state = g_form.getValue('state');
if(g_form.getValue('assigned_to') == '') {
//Remove any existing field message, set comments mandatory, and show a new field message
g_form.setMandatory('assigned_to', true);
g_form.showFieldMsg('assigned_to','Assigned to is mandatory when closing the task.','error');
return false; //Abort submission
}
if(state == 4) // or whatever your closed incomplete value is
g_form.setValue('state', state);
else
g_form.setValue('state', '3');
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'close_Task'); //MUST call the 'Action name' set in this UI Action
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2015 07:20 AM
Hi Karen,
Typically a button like that would just set the state of the task to closed. What's the purpose of using the button if the user is able to use the field to set the closed status?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2015 09:39 AM
Brad thanks for that.
I did not initially set it up and I am not sure of the logic that went into setting it like that. I am not sure if it was requested by the business with little understanding of the purpose. This is why I am trying to do some cleanup in various places. I've seen much inconsistency.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2015 09:59 AM
You should be able to say:
function closeTask(){
var state = g_form.getValue('state');
if(g_form.getValue('assigned_to') == '') {
//Remove any existing field message, set comments mandatory, and show a new field message
g_form.setMandatory('assigned_to', true);
g_form.showFieldMsg('assigned_to','Assigned to is mandatory when closing the task.','error');
return false; //Abort submission
}
if(state == 4) // or whatever your closed incomplete value is
g_form.setValue('state', state);
else
g_form.setValue('state', '3');
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'close_Task'); //MUST call the 'Action name' set in this UI Action
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2015 06:59 AM
Mike thank you, I am just getting back to this project. I will try that and let you know if I was successful.