Actual start and actual end date not working in release tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2022 05:15 AM
Hi,
there is requirement on Release task, i,e. I would like to add a 'Close Task' button to the top of the Task form for a one click 'Close Complete' state option. When the Close task button is selected, the user will populate the Actual Start date if it is not already entered and select 'Save', the Task 'State' will be 'Closed Complete', the Actual End Date will be populated with the current date and time and the user will be returned to the Release Phase.
- I tried with below script but not working , can any one help.
function closeTask(){
//var state =g_form.getValue('state');
if(g_form.getValue('work_start') ==''){
g_form.setMandatory('work_start', true);
g_form.showFieldMsg('work_start', 'actual start date is mandatory');
return false;
}
g_form.setValue('state', 3);
//g_form.setValue('work_end',gs.nowDateTime());
gsftsubmit(null,g_form.gryFormatElement(),'close_sc_task' );
}
current.work_end=new GlideDateTime();
current.update;
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2022 08:23 AM
When creating client side UI Actions for UI16 one needs to consider that
- the same piece of code will be executed both on the client side as the button is pressed and on the server side when the processor takes over
- the form is not automatically submitted, explicit call to gsftSubmit is needed; b.t.w. JavaScript is case sensitive, so gsftsubmit is not the same as gsftSubmit.
The widely used strategy to make sure that just the right part of the script is executed both on client side and server side is to place everything into functions, except the code that checks for the server side. The client side part being kick-started in a function is a UI Action definition requirement.
So something like this:
if (typeof window == 'undefined')
executeServerSidePart();
function executeClientSidePart () { // This name must be used in field Onclick of the UI Action
// This is where execution on the client side will begin
}
function executeServerSidePart () {
// This is where execution on the server side will begin
}
In the function that gets to be executed on the client side, one should make the state change (and perhaps other required changes), then check for mandatory fields and if everything is OK call the submit instruction:
function executeClientSidePart () { // This name must be used in field Onclick of the UI Action
// This is where execution on the client side will begin
// Change the state and as a result the relevant fields would be made mandatory
// Of course this assumes there are UI Policies defined that make the relevant fields mandatory when the state is 3
g_form.setValue('state', 3);
// Submit the form only if all mandatory checks are fulfilled
if (g_form.mandatoryCheck())
gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
}
g_form.mandatoryCheck()
returns true if all mandatory fields have valid values (or if there are no mandatory fields, of course). It will also show the standard OOB warnings to the user that they need to fill in the empty mandatory fields - so no need to add your custom one.
As visible there is no need to manage mandatory states in the UI Action code, those should be managed independently in Data Policies that a configured to act on client side too. At worst by UI Policies.
In the function that gets executed on the server side, one should update those fields that are protected by ACLs and are not otherwise writable by the current user, one should update the current record and optionally set up redirection. E.g:
function executeServerSidePart () {
// This is where execution on the server side will begin
current.state = 3;
current.update();
action.setRedirectURL(current);
}
The updating of field work_end
should be done in a Business Rule, not in the UI Action script. Thus making work_end
is not even needed. All in all your complete final script could be:
if (typeof window == 'undefined')
executeServerSidePart();
function executeClientSidePart () { // This name must be used in field Onclick of the UI Action
// This is where execution on the client side will begin
// Change the state and as a result the relevant fields would be made mandatory
// Of course this assumes there are UI Policies defined that make the relevant fields mandatory when the state is 3
g_form.setValue('state', 3);
// Submit the form only if all mandatory checks are fulfilled
if (g_form.mandatoryCheck())
gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
}
function executeServerSidePart () {
// This is where execution on the server side will begin
current.state = 3;
current.update();
action.setRedirectURL(current);
}
Of course, I'm assuming the Action name of the UI Action is close_sc_task
. If it is not (most likely it is not), the server side part will not be executed. Adjust it as needed. It also cannot be blank.
Don't forget to add a (before) Business Rule that sets the work_end
to "now" when State changes to 3. You should also create a Data or UI Policy that makes field Actual start date (work_start
) mandatory when state is 3; Actual end date will be updated by the BR so no need to make that one mandatory.