- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 11:06 AM
Hello,
my cancel button on the portal widget is not setting the state to cancelled on the parent form when it's clicked,
I need the cancelled state of 107 that is on the parent form, table name "x_g_duas_abm_contract_action_review" to be set once a user pushes the cancel button on the portal form of the child task form. I have my code listed below and it's not working.
Script
(function(){
data.pickupMsg = gs.getMessage(options.pickup_msg);
var gr = $sp.getRecord();
if (gr == null)
return;
data.canRead = gr.canRead();
if (!data.canRead)
return;
var agent = "";
var a = $sp.getField(gr, 'assigned_to');
if (a != null)
agent = a.display_value;
if (gr.getTableName() == 'x_g_duas_abm_unfunded_requirement') {
var fields = $sp.getFields(gr, 'number,state,mission_priority,sys_created_on');
fields[2].label = 'Priority';
}
else if (gr.getTableName() == 'x_g_duas_abm_abm_help_ticket') {
var fields = $sp.getFields(gr, 'number,state,sys_created_on');
data.helpTicket = true;
}
else
var fields = $sp.getFields(gr, 'number,state,priority,sys_created_on');
if (gr.getValue("sys_mod_count") > 0)
fields.push($sp.getField(gr, 'sys_updated_on'));
if (gr.getValue('price') > 0)
fields.push($sp.getField(gr, 'price'));
if (gr.getValue('recurring_price') > 0) {
var rp = $sp.getField(gr, 'recurring_price');
if (gr.isValidField("recurring_price"))
rp.display_value = rp.display_value + " " + gr.getDisplayValue("recurring_frequency");
fields.push(rp);
}
if (gr.isValidField("quantity"))
fields.push($sp.getField(gr, 'quantity'));
if (gs.getUserID() == gr.getValue("opened_by"))
data.isMine = true;
else
data.isMine = false;
data.tableLabel = gr.getLabel();
data.fields = fields;
data.variables = new global.GlobalServiceCatalogUtil().getVariablesForTask(gr, true);
data.agent = agent;
data.agentPossible = gr.isValidField("assigned_to");
if(data.agentPossible){
data.assignedToMe = gr.getValue("assigned_to") == gs.getUserID();
} else{
data.assignedToMe = false;
}
data.table = gr.getTableName();
data.sys_class_name = gr.getValue("sys_class_name");
data.sys_id = gr.getUniqueValue();
data.state = gr.getValue('state');
data.more_info = gr.getValue('more_info');
data.variableSummarizerWidget = $sp.getWidget('sc-variable-summarizer', {'variables' : data.variables, 'toggle' : true, 'task' : fields[0].value});
if(input){
if (input.action == 'update_state') {
data.more_info = false;
gr.setValue('more_info', false);
gr.comments = "[code]<b>More Information Submitted</b> by [/code]" + gs.getUserDisplayName();
gr.update();
} else if (input.action == 'cancel') {
gr.setValue('state', 7);
gr.comments = "[code]<b>Request Cancelled</b>[/code] by " + gs.getUserDisplayName();
gr.update();
var flowGR = new GlideRecord('sys_flow_context');
flowGR.addQuery('source_record', data.sys_id);
flowGR.query();
flowGR.next();
sn_fd.FlowAPI.cancel(flowGR.getValue('sys_id'), 'Cancelled by submitter');
} else if (input.action == 'complete'){
if (gr.getTableName() == 'x_g_duas_abm_srrb')
gr.setValue('state', -17);
else
gr.setValue('state', 3);
gr.comments = "Review task completed by " + gs.getUserDisplayName();
gr.update();
}
}
if(input){
if (input.action == 'update_state') {
data.more_info = false;
gr.setValue('more_info', false);
gr.comments = "[code]<b>More Information Submitted</b> by [/code]" + gs.getUserDisplayName();
gr.update();
} else if (input.action == 'cancel') {
gr.setValue('state', 7);
gr.comments = "[code]<b>Request Cancelled</b>[/code] by " + gs.getUserDisplayName();
gr.update();
var flowGR = new GlideRecord('sys_flow_context');
flowGR.addQuery('source_record', data.sys_id);
flowGR.query();
flowGR.next();
sn_fd.FlowAPI.cancel(flowGR.getValue('sys_id'), 'Cancelled by submitter');
} else if (input.action == 'cancelled'){
if (gr.getTableName() == 'x_g_duas_abm_contract_action_review')
gr.setValue('state', -17);
else
gr.setValue('state', 107);
gr.comments = "Review task completed by " + gs.getUserDisplayName();
gr.update();
}
}
})()
Client controller:
api.controller = function($scope, $rootScope, spUtil) {
var c = this
spUtil.recordWatch($scope, $scope.data.table, "sys_id=" + $scope.data.sys_id);
// Temporary function definition to use until we grab the g_form.isUserModified() function
var isUserModified = function() {
return false;
};
$rootScope.$on('spModel.gForm.rendered', function(e, gFormInstance) {
if (gFormInstance.getTableName().indexOf("x_g_duas_abm") > -1) {
isUserModified = gFormInstance.isUserModified;
$scope.disableResubmit = isUserModified();
}
});
c.action = function() {
$rootScope.$broadcast("action.initiated");
c.server.get({
action: 'update_state'
}).then(function() {});
}
c.cancelAction = function() {
$rootScope.$broadcast("action.initiated");
c.server.get({
action: 'cancel'
}).then(function() {});
}
c.completeAction = function() {
$rootScope.$broadcast("action.initiated");
c.server.get({
action: 'complete'
}).then(function() {});
}
c.showContractActionReviewOptions = function (){
console.log(c.data);
return (c.data.table == 'x_g_duas_abm_contract_action_review_task' &&
c.data.assignedToMe);
}
c.showSRRBOptions = function (){
console.log(c.data);
return (c.data.table == 'x_g_duas_abm_srrb');
}
$scope.disableResubmit = false;
$rootScope.$on("field.change", function(e, parms) {
console.log(parms.field.name);
if (parms.field.name != "comments" && parms.field.name != "work_notes") {
$scope.disableResubmit = isUserModified();
}
});
$rootScope.$on("sp.form.record.updated", function() {
$scope.disableResubmit = false;
});
}
Please if anyone has a clue to what is wrong with my scripts please help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2024 01:51 AM
Hi @Andre241 ,
Can you try the below code:
Server Script:
(function() {
data.pickupMsg = gs.getMessage(options.pickup_msg);
var gr = $sp.getRecord();
if (gr == null) return;
data.canRead = gr.canRead();
if (!data.canRead) return;
var agent = "";
var a = $sp.getField(gr, 'assigned_to');
if (a != null) agent = a.display_value;
var fields;
switch (gr.getTableName()) {
case 'x_g_duas_abm_unfunded_requirement':
fields = $sp.getFields(gr, 'number,state,mission_priority,sys_created_on');
fields[2].label = 'Priority';
break;
case 'x_g_duas_abm_abm_help_ticket':
fields = $sp.getFields(gr, 'number,state,sys_created_on');
data.helpTicket = true;
break;
default:
fields = $sp.getFields(gr, 'number,state,priority,sys_created_on');
}
if (gr.getValue("sys_mod_count") > 0) fields.push($sp.getField(gr, 'sys_updated_on'));
if (gr.getValue('price') > 0) fields.push($sp.getField(gr, 'price'));
if (gr.getValue('recurring_price') > 0) {
var rp = $sp.getField(gr, 'recurring_price');
if (gr.isValidField("recurring_price")) rp.display_value += " " + gr.getDisplayValue("recurring_frequency");
fields.push(rp);
}
if (gr.isValidField("quantity")) fields.push($sp.getField(gr, 'quantity'));
data.isMine = gs.getUserID() == gr.getValue("opened_by");
data.tableLabel = gr.getLabel();
data.fields = fields;
data.variables = new global.GlobalServiceCatalogUtil().getVariablesForTask(gr, true);
data.agent = agent;
data.agentPossible = gr.isValidField("assigned_to");
data.assignedToMe = data.agentPossible && gr.getValue("assigned_to") == gs.getUserID();
data.table = gr.getTableName();
data.sys_class_name = gr.getValue("sys_class_name");
data.sys_id = gr.getUniqueValue();
data.state = gr.getValue('state');
data.more_info = gr.getValue('more_info');
data.variableSummarizerWidget = $sp.getWidget('sc-variable-summarizer', { 'variables': data.variables, 'toggle': true, 'task': fields[0].value });
if (input) {
if (input.action == 'update_state') {
data.more_info = false;
gr.setValue('more_info', false);
gr.comments = "[code]<b>More Information Submitted</b> by [/code]" + gs.getUserDisplayName();
gr.update();
} else if (input.action == 'cancel') {
gr.setValue('state', 7);
gr.comments = "[code]<b>Request Cancelled</b>[/code] by " + gs.getUserDisplayName();
gr.update();
var flowGR = new GlideRecord('sys_flow_context');
flowGR.addQuery('source_record', data.sys_id);
flowGR.query();
if (flowGR.next()) sn_fd.FlowAPI.cancel(flowGR.getValue('sys_id'), 'Cancelled by submitter');
} else if (input.action == 'complete') {
gr.setValue('state', gr.getTableName() == 'x_g_duas_abm_srrb' ? -17 : 3);
gr.comments = "Review task completed by " + gs.getUserDisplayName();
gr.update();
} else if (input.action == 'cancelled') {
if (gr.getTableName() == 'x_g_duas_abm_contract_action_review') {
gr.setValue('state', 107);
gr.comments = "Review task completed by " + gs.getUserDisplayName();
gr.update();
}
}
}
})();
Client Controller:
api.controller = function($scope, $rootScope, spUtil) {
var c = this;
spUtil.recordWatch($scope, $scope.data.table, "sys_id=" + $scope.data.sys_id);
var isUserModified = function() {
return false;
};
$rootScope.$on('spModel.gForm.rendered', function(e, gFormInstance) {
if (gFormInstance.getTableName().indexOf("x_g_duas_abm") > -1) {
isUserModified = gFormInstance.isUserModified;
$scope.disableResubmit = isUserModified();
}
});
c.action = function() {
$rootScope.$broadcast("action.initiated");
c.server.get({ action: 'update_state' }).then(function() {});
};
c.cancelAction = function() {
$rootScope.$broadcast("action.initiated");
c.server.get({ action: 'cancel' }).then(function() {});
};
c.completeAction = function() {
$rootScope.$broadcast("action.initiated");
c.server.get({ action: 'complete' }).then(function() {});
};
c.showContractActionReviewOptions = function() {
return c.data.table === 'x_g_duas_abm_contract_action_review_task' && c.data.assignedToMe;
};
c.showSRRBOptions = function() {
return c.data.table === 'x_g_duas_abm_srrb';
};
$scope.disableResubmit = false;
$rootScope.$on("field.change", function(e, parms) {
if (parms.field.name !== "comments" && parms.field.name !== "work_notes") {
$scope.disableResubmit = isUserModified();
}
});
$rootScope.$on("sp.form.record.updated", function() {
$scope.disableResubmit = false;
});
};
I started answering community questions recently. If my answer helped you in any way, please mark it as helpful or correct. It would be a great boost.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2024 01:51 AM
Hi @Andre241 ,
Can you try the below code:
Server Script:
(function() {
data.pickupMsg = gs.getMessage(options.pickup_msg);
var gr = $sp.getRecord();
if (gr == null) return;
data.canRead = gr.canRead();
if (!data.canRead) return;
var agent = "";
var a = $sp.getField(gr, 'assigned_to');
if (a != null) agent = a.display_value;
var fields;
switch (gr.getTableName()) {
case 'x_g_duas_abm_unfunded_requirement':
fields = $sp.getFields(gr, 'number,state,mission_priority,sys_created_on');
fields[2].label = 'Priority';
break;
case 'x_g_duas_abm_abm_help_ticket':
fields = $sp.getFields(gr, 'number,state,sys_created_on');
data.helpTicket = true;
break;
default:
fields = $sp.getFields(gr, 'number,state,priority,sys_created_on');
}
if (gr.getValue("sys_mod_count") > 0) fields.push($sp.getField(gr, 'sys_updated_on'));
if (gr.getValue('price') > 0) fields.push($sp.getField(gr, 'price'));
if (gr.getValue('recurring_price') > 0) {
var rp = $sp.getField(gr, 'recurring_price');
if (gr.isValidField("recurring_price")) rp.display_value += " " + gr.getDisplayValue("recurring_frequency");
fields.push(rp);
}
if (gr.isValidField("quantity")) fields.push($sp.getField(gr, 'quantity'));
data.isMine = gs.getUserID() == gr.getValue("opened_by");
data.tableLabel = gr.getLabel();
data.fields = fields;
data.variables = new global.GlobalServiceCatalogUtil().getVariablesForTask(gr, true);
data.agent = agent;
data.agentPossible = gr.isValidField("assigned_to");
data.assignedToMe = data.agentPossible && gr.getValue("assigned_to") == gs.getUserID();
data.table = gr.getTableName();
data.sys_class_name = gr.getValue("sys_class_name");
data.sys_id = gr.getUniqueValue();
data.state = gr.getValue('state');
data.more_info = gr.getValue('more_info');
data.variableSummarizerWidget = $sp.getWidget('sc-variable-summarizer', { 'variables': data.variables, 'toggle': true, 'task': fields[0].value });
if (input) {
if (input.action == 'update_state') {
data.more_info = false;
gr.setValue('more_info', false);
gr.comments = "[code]<b>More Information Submitted</b> by [/code]" + gs.getUserDisplayName();
gr.update();
} else if (input.action == 'cancel') {
gr.setValue('state', 7);
gr.comments = "[code]<b>Request Cancelled</b>[/code] by " + gs.getUserDisplayName();
gr.update();
var flowGR = new GlideRecord('sys_flow_context');
flowGR.addQuery('source_record', data.sys_id);
flowGR.query();
if (flowGR.next()) sn_fd.FlowAPI.cancel(flowGR.getValue('sys_id'), 'Cancelled by submitter');
} else if (input.action == 'complete') {
gr.setValue('state', gr.getTableName() == 'x_g_duas_abm_srrb' ? -17 : 3);
gr.comments = "Review task completed by " + gs.getUserDisplayName();
gr.update();
} else if (input.action == 'cancelled') {
if (gr.getTableName() == 'x_g_duas_abm_contract_action_review') {
gr.setValue('state', 107);
gr.comments = "Review task completed by " + gs.getUserDisplayName();
gr.update();
}
}
}
})();
Client Controller:
api.controller = function($scope, $rootScope, spUtil) {
var c = this;
spUtil.recordWatch($scope, $scope.data.table, "sys_id=" + $scope.data.sys_id);
var isUserModified = function() {
return false;
};
$rootScope.$on('spModel.gForm.rendered', function(e, gFormInstance) {
if (gFormInstance.getTableName().indexOf("x_g_duas_abm") > -1) {
isUserModified = gFormInstance.isUserModified;
$scope.disableResubmit = isUserModified();
}
});
c.action = function() {
$rootScope.$broadcast("action.initiated");
c.server.get({ action: 'update_state' }).then(function() {});
};
c.cancelAction = function() {
$rootScope.$broadcast("action.initiated");
c.server.get({ action: 'cancel' }).then(function() {});
};
c.completeAction = function() {
$rootScope.$broadcast("action.initiated");
c.server.get({ action: 'complete' }).then(function() {});
};
c.showContractActionReviewOptions = function() {
return c.data.table === 'x_g_duas_abm_contract_action_review_task' && c.data.assignedToMe;
};
c.showSRRBOptions = function() {
return c.data.table === 'x_g_duas_abm_srrb';
};
$scope.disableResubmit = false;
$rootScope.$on("field.change", function(e, parms) {
if (parms.field.name !== "comments" && parms.field.name !== "work_notes") {
$scope.disableResubmit = isUserModified();
}
});
$rootScope.$on("sp.form.record.updated", function() {
$scope.disableResubmit = false;
});
};
I started answering community questions recently. If my answer helped you in any way, please mark it as helpful or correct. It would be a great boost.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 08:17 AM
I'll give this a shot, thank you.