- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-20-2022 01:16 AM
Hi
I want to add the number field of a record (if it exists) into a field in another table. Is it best to run a business rule, or to specify this in the dictionary entry for the reference field? Then next questions is, how do I do this?
All help is highly appreciated š
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-20-2022 01:21 AM
Best way is to use Business Rule only if you want to achieve it when any Changes or Update happened in your record.
And if you want to achieve it for existing record, you should go with Fix Script.
So based on your requirement you can implement by GlideRecord() another table and update the field.
NOTE: For Reference field, sys_id is stored in the backend.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-20-2022 03:58 AM
Sorry but what is this 'Customer service request integration'??
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-20-2022 04:29 AM
Customer service request integration is what is called in the ui action to create request from case;
new ServiceManagementRequestUtils().createRequestUIAction(current,action);
This is the read-only script:
var ServiceManagementRequestUtils = Class.create();
ServiceManagementRequestUtils.prototype = {
initialize: function() {
},
copyFieldsFromCaseToRequest: function(requestGr, caseGr) {
var ep = new GlideScriptedExtensionPoint().getExtensions(RequestManagementIntegrationConstants.REQUEST_EXTENSION_POINT);
//If there is any other new extension instance other than the OOB one, concat them together
//The extension instance with higher order number would overwrite the one with lower order number
var point;
for(var i = 0; i < ep.length; i ++){
point = ep[i];
point.copyFieldsFromCaseToRequest(requestGr, caseGr);
}
},
copyDomainFromRequestToChildren: function(requestGr){
var caseRecord = new GlideRecord(RequestManagementIntegrationConstants.CASE_TABLE);
caseRecord.get(requestGr.parent);
caseRecord.query();
//Check if parent is case. Check state of parent.
if(caseRecord.next() && !this.invalidCaseStates(caseRecord)){
var ep = new GlideScriptedExtensionPoint().getExtensions(RequestManagementIntegrationConstants.REQUEST_EXTENSION_POINT);
//If there is any other new extension instance other than the OOB one, concat them together
//The extension instance with higher order number would overwrite the one with lower order number
var point;
for(var i = 0; i < ep.length; i ++){
point = ep[i];
point.copyDomainFromRequestToChildren(requestGr);
}
}
},
createCaseFromRequest: function(requestGr){
//Copy from request to case
var extPt = new GlideScriptedExtensionPoint().getExtensions(RequestManagementIntegrationConstants.REQUEST_EXTENSION_POINT);
//If there is any other new extension instance other than the OOB one, override with the latest one
var canUserCreateCase = false;
for(var j = 0; j < extPt.length; j ++){
var pt = extPt[j];
canUserCreateCase = pt.canUserCreateCase(requestGr);
}
if(canUserCreateCase){
//Create case
var caseGr = new GlideRecord(RequestManagementIntegrationConstants.CASE_TABLE);
caseGr.initialize();
//Copy from request to case
var ep = new GlideScriptedExtensionPoint().getExtensions(RequestManagementIntegrationConstants.REQUEST_EXTENSION_POINT);
//If there is any other new extension instance other than the OOB one, concat them together
//The extension instance with higher order number would overwrite the one with lower order number
var point;
for(var i = 0; i < ep.length; i ++){
point = ep[i];
point.copyFieldsFromRequestToCase(requestGr, caseGr);
}
//Set Intitiated as Requested field to true
caseGr.initiated_as_request = true;
var caseId = caseGr.insert();
if(!gs.nil(caseId))
requestGr.parent = caseId;
//Change Requested For to be the Case Contact if different
if(!gs.nil(caseGr.contact) && caseGr.contact != requestGr.requested_for)
requestGr.requested_for = caseGr.contact;
}
},
//Check for consumer role and set consumer
createConsumerCaseFromRequest: function(requestGr){
if(gs.hasRole(RequestManagementIntegrationConstants.CSM_CONSUMER_ROLE) && !gs.hasRole(RequestManagementIntegrationConstants.ADMIN_ROLE)){
//Create case
var caseGr = new GlideRecord(RequestManagementIntegrationConstants.CASE_TABLE);
caseGr.initialize();
//Copy from request to case
var ep = new GlideScriptedExtensionPoint().getExtensions(RequestManagementIntegrationConstants.REQUEST_EXTENSION_POINT);
//If there is any other new extension instance other than the OOB one, concat them together
//The extension instance with higher order number would overwrite the one with lower order number
var point;
for(var i = 0; i < ep.length; i ++){
point = ep[i];
point.copyFieldsFromRequestToConsumerCase(requestGr, caseGr);
}
//Set Intitiated as Requested field to true
caseGr.initiated_as_request = true;
var caseId = caseGr.insert();
if(!gs.nil(caseId))
requestGr.parent = caseId;
}
},
copyFieldsFromRequestItemToCase: function(requestGr){
var caseRecord = new GlideRecord(RequestManagementIntegrationConstants.CASE_TABLE);
if(caseRecord.get(requestGr.parent) && !this.invalidCaseStates(caseRecord)){
//Get the request item
var requestItemGr = new GlideRecord(RequestManagementIntegrationConstants.REQUEST_ITEM_TABLE);
requestItemGr.addQuery("request",requestGr.sys_id);
requestItemGr.query();
//Assumption as of now is only one request item per request. If this changes, this logic needs to be changed.
if(requestItemGr.next()){
var ep = new GlideScriptedExtensionPoint().getExtensions(RequestManagementIntegrationConstants.REQUEST_EXTENSION_POINT);
//If there is any other new extension instance other than the OOB one, concat them together
//The extension instance with higher order number would overwrite the one with lower order number
var point;
//Copy fields from request item to case. (Short description OOTB)
for(var i = 0; i < ep.length; i ++){
point = ep[i];
point.copyFieldsFromRequestItemToCase(requestItemGr, caseRecord);
}
caseRecord.update();
}
}
},
canUserAccessRequest: function(accessToRequestList) {
//If there is any other new extension instance other than the OOB one, concat them together
//The extension instance with higher order number would overwrite the one with lower order number
var ep = new GlideScriptedExtensionPoint().getExtensions(RequestManagementIntegrationConstants.REQUEST_EXTENSION_POINT);
var requestRoles = [];
var point;
for(var i = 0; i < ep.length; i++){
point = ep[i];
if (!gs.nil(accessToRequestList) && accessToRequestList === true){
requestRoles = point.getRolesForRequestList(requestRoles);
} else {
requestRoles = point.getRolesForRequestIntegration(requestRoles);
}
}
var answer = false;
for(var j = 0; j < requestRoles.length; j++){
if(gs.hasRole(requestRoles[j])) {
answer = true;
break;
}
}
return answer;
},
updateCaseWithRequestAssociation: function(requestGr, caseGr) {
//If there is any other new extension instance other than the OOB one, concat them together
//The extension instance with higher order number would overwrite the one with lower order number
var ep = new GlideScriptedExtensionPoint().getExtensions(RequestManagementIntegrationConstants.REQUEST_EXTENSION_POINT);
var point;
for(var i = 0; i < ep.length; i++){
point = ep[i];
point.updateCaseWithRequestAssociation(requestGr, caseGr);
}
},
createRequestFromCase: function(requestGr){
var caseRecord = new GlideRecord(RequestManagementIntegrationConstants.CASE_TABLE);
if(caseRecord.get(requestGr.parent) && !this.invalidCaseStates(caseRecord)){
//Copy over fields from the parent to request
var caseGr = requestGr.parent;
this.copyFieldsFromCaseToRequest(requestGr, caseGr);
//Update work notes on case
this.updateCaseWithRequestAssociation(requestGr, caseRecord);
caseRecord.update();
}
},
createRequestUIAction: function(current,action){
//Update saves case before going to the catalog homepage
current.update();
var url;
var activeCatalogsCount = sn_sc.Catalog.getCatalogCount();
if (activeCatalogsCount === 1) {
url = "catalog_home.do?sysparm_view=catalog_default&sysparm_parent_table=" + current.sys_class_name + "&sysparm_parent_sys_id=" + current.sys_id;
}
else {
url = "catalogs_home.do?sysparm_view=catalogs_default&sysparm_parent_table=" + current.sys_class_name + "&sysparm_parent_sys_id=" + current.sys_id;
}
action.setRedirectURL(url);
},
canCreateRequest : function(caseGr) {
var isRequestAllowed = false;
if (this.canUserAccessRequest() && !this.invalidCaseStates(caseGr))
isRequestAllowed = true;
//For a child of a major case, hide the Create Request UI action
if (!gs.nil(caseGr.parent) && caseGr.parent.major_case_state == RequestManagementIntegrationConstants.MAJOR_CASE_ACCEPTED)
isRequestAllowed = false;
return isRequestAllowed;
},
updateCaseWorkNotesWithRequestFields: function(requestGr, field) {
var caseRecord = new GlideRecord(RequestManagementIntegrationConstants.CASE_TABLE);
if(caseRecord.get(requestGr.parent) && !this.invalidCaseStates(caseRecord)){
var ep = new GlideScriptedExtensionPoint().getExtensions(RequestManagementIntegrationConstants.REQUEST_EXTENSION_POINT);
//If there is any other new extension instance other than the OOB one, concat them together
//The extension instance with higher order number would overwrite the one with lower order number
var point;
for(var i = 0; i < ep.length; i ++){
point = ep[i];
point.updateCaseWorkNotesWithRequestFields(requestGr, caseRecord, field);
}
caseRecord.update();
}
},
invalidCaseStates: function(caseGr){
//If case is one of the following states, do not update work notes or show UI action.Also not show for order case.
if(caseGr.state == RequestManagementIntegrationConstants.CASE_STATE_CLOSED ||
caseGr.state == RequestManagementIntegrationConstants.CASE_STATE_RESOLVED ||
caseGr.state == RequestManagementIntegrationConstants.CASE_STATE_CANCELED ||
caseGr.major_case_state == RequestManagementIntegrationConstants.MAJOR_CASE_ACCEPTED){
return true;
}
return false;
},
updateCaseWithRITMUpdates: function(ritmGr) {
//BR already validates that ritm has request parent as not empty
var caseRecord = new GlideRecord(RequestManagementIntegrationConstants.CASE_TABLE);
if(caseRecord.get(ritmGr.request.parent) && !this.invalidCaseStates(caseRecord)){
//If there is any other new extension instance other than the OOB one, concat them together
//The extension instance with higher order number would overwrite the one with lower order number
var ep = new GlideScriptedExtensionPoint().getExtensions(RequestManagementIntegrationConstants.REQUEST_EXTENSION_POINT);
var point;
for(var i = 0; i < ep.length; i++){
point = ep[i];
point.updateCaseWithRITMUpdates(ritmGr, caseRecord);
}
caseRecord.update();
}
},
/**
* Gets the list of request(s) associated to a case
*/
getRequestsAssociatedToCase : function(caseSysId) {
var relatedRequests;
var requests = [];
var requestGr = new GlideRecord(RequestManagementIntegrationConstants.REQUEST_TABLE);
requestGr.addQuery(RequestManagementIntegrationConstants.REQUEST_PARENT_FIELD,caseSysId);
requestGr.query();
while (requestGr.next()) {
var reqItems = this._getRequestedItems(requestGr.sys_id);
if (reqItems.length > 0) {
var request = {};
request[RequestManagementIntegrationConstants.KEY_NUMBER] = requestGr.number+'';
request[RequestManagementIntegrationConstants.KEY_SYSID] = requestGr.sys_id+'';
request[RequestManagementIntegrationConstants.KEY_TABLE] = requestGr.getTableName()+'';
request[RequestManagementIntegrationConstants.KEY_REQUEST_STATE] = requestGr.request_state.getDisplayValue()+'';
request[RequestManagementIntegrationConstants.KEY_ITEMS] = reqItems;
requests.push(request);
}
}
if (!gs.nil(requests) && requests.length > 0) {
relatedRequests = {};
relatedRequests[RequestManagementIntegrationConstants.KEY_DISPLAY] = RequestManagementIntegrationConstants.RELATED_REQUEST;
relatedRequests[RequestManagementIntegrationConstants.KEY_REQUEST] = requests;
}
return relatedRequests;
},
_getRequestedItems : function(requestId) {
var reqItems = [];
var reqItemGr = new GlideRecord(RequestManagementIntegrationConstants.REQUEST_ITEM_TABLE);
reqItemGr.addQuery(RequestManagementIntegrationConstants.KEY_REQUEST,requestId);
reqItemGr.query();
while(reqItemGr.next() && reqItemGr.canRead()) {
var reqItem = {};
reqItem[RequestManagementIntegrationConstants.KEY_NUMBER] = reqItemGr.number+'';
reqItem[RequestManagementIntegrationConstants.KEY_SYSID] = reqItemGr.sys_id+'';
reqItem[RequestManagementIntegrationConstants.KEY_SHORT_DESC] = reqItemGr.short_description+'';
reqItem[RequestManagementIntegrationConstants.KEY_TABLE] = reqItemGr.getTableName()+'';
reqItem[RequestManagementIntegrationConstants.KEY_CAT_ITEM] = reqItemGr.cat_item.getDisplayValue()+'';
reqItems.push(reqItem);
}
return reqItems;
},
/*
* Function which gets the Encoded Query String which can be applied to the sc_cat_item Table to filter out the catalog Items
* Output: Encoded Query String
*
*/
getVariableSet_AssociateCondition : function(){
var result = false;
var ep = new GlideScriptedExtensionPoint().getExtensions(RequestManagementIntegrationConstants.REQUEST_EXTENSION_POINT);
//If there is any other new extension instance other than the OOB one The extension instance with higher order number would overwrite the one with lower order number
var point;
for(var i = 0; i < ep.length; i ++){
point = ep[i];
result = point.getVariableSet_AssociateCondition();
}
return result;
},
/*
* Function which handles bulk association of associating Catalog Item to CSM VS to the Catalog Item
* This function reads the extension point and gets the Encoded Query condition to filter out the Catalog Items
* It then iterates through the Catalog Item and add in the CSM Variable Set
*/
addCSMVariableSet : function(){
var encodedQuery = this.getVariableSet_AssociateCondition();
var result = [];
var catItemGr = new GlideRecord(RequestManagementIntegrationConstants.SC_CATALOG_ITEM);
catItemGr.addActiveQuery();
catItemGr.addEncodedQuery(encodedQuery);
catItemGr.query();
while(catItemGr.next()){
var details = {};
var ioRecord = this.associateCSMVariableSet(catItemGr);
if(!gs.nil(ioRecord)){
var catMsg = " Catalog Item ID: " + catItemGr.sys_id + " Variable Set Record: " + ioRecord;
details.message = gs.getMessage("{0}",catMsg);
}
else{
details.errorMessage = gs.getMessage("Unable to add for {0} for Catalog item with Id {1}",RequestManagementIntegrationConstants.CSM_VARIABLE_SET_INTERNAL_NAME,catItemGr.sys_id);
}
result.push(details);
}
return result;
},
/*
* Function which associates CSM Variable Set to the Catalog Item
*/
associateCSMVariableSet : function(catalogGr){
var result;
var variableSetId = this._getCSMVariableSet();
if(!gs.nil(variableSetId) && !gs.nil(variableSetId.id)){
result = new global.RequestManagementUtils().upsertCSMVariableSet(variableSetId.id,catalogGr.sys_id,variableSetId.order);
}
return result;
},
/*
* Function which gets the CSM Variable Set ID and Order
*/
_getCSMVariableSet: function(){
var variableGr = new GlideRecord(RequestManagementIntegrationConstants.VARIABLE_SET_TABLE);
variableGr.addQuery("internal_name",RequestManagementIntegrationConstants.CSM_VARIABLE_SET_INTERNAL_NAME);
variableGr.query();
if(variableGr.next()){
return {"id":variableGr.sys_id,"order":variableGr.order};
}
},
type: 'ServiceManagementRequestUtils'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-20-2022 05:12 AM
Not sure why my reply doesnt get posted.. Anyway this is the scripted ui action:
ServiceManagementRequestUtils().createRequestUIAction(current,action);
It is read only and I cannot edit, nor can I fix in the scripted extension points
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-20-2022 02:34 AM
Hi, I was wondering, why don't you use OOB Request tab in related lists...
What if there are multiple requests for one cunstomer service case?
Think and implement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-20-2022 04:13 AM
Hi @Naga Ravindra R
I limit one req per case, whereas the req may have many items.. I do use the related list field, but have other customization that use the related records reference fields.
I just find it strange that I can not add the req number into my related field, and it is really the last part of my puzzle š