Update system property using Scripted REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
Hi Team,
We want to update system properties present in different scope. So, if the AuthToken (which will be manually populated in all three applications (CSM/FSM/ITSM) ) matches with the AuthToken coming in payload then the remaining 4 system properties of the appications will get updated.
Business Requirement: We have single Scripted REST API present in Dependent applcation (x_xyz_dependent) , with which we have to update the system properties present in different scopes if the AuthToken present in that scope (Application) matches with the AuthToken coming in payload the remaining system properties( 4) should also get updated. We call our main Script Include from this scripted REST API anf there we match the authToken, if the authToken matches then we send the values of other system properties to script includes of their respective scopes to update. But other system property are not updating. I have created Cross Scope access priviledge from Dependent scope to 3 apps (CSM/ITSM/FSM). I have placed logs(gs.info) in Script Includes (CSM/FSM/ITSM) and confirm that the logs are coming that means script includes are reachable still system properties are not updating.
Payload:
{"sessionId":"TestSession",
"userName":"Test User",
"userEmail":"testuser1@gmail.com",
"authToken":"aa60c16ff16afe7583d0",
"userRegion":"US",
"accountID":"G6TShHJCS7B4"}
System Properties:
FSM :
1. x_xyz_fsm.authToken
2. x_xyz_fsm.name
3. x_xyz_fsm.email
4. x_xyz_fsm.accountID
5 x_xyz_fsm.region
CSM:
1. x_xyz_csm.authToken
2. x_xyz_csm.name
3. x_xyz_csm.email
4. x_xyz_csm.accountID
5 x_xyz_csm.region
ITSM:
1. x_xyz_itsm.authToken
2. x_xyz_itsm.name
3. x_xyz_itsm.email
4. x_xyz_itsm.accountID
5 x_xyz_itsm.region
Scripted REST API:
HTTP method: POST
Scope of Scripted REST API is : x_xyz_dependent
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var ship = new PostComments().addComments(request);
var parsedData = JSON.parse(ship);
response.setBody(parsedData);
})(request, response);
Script Include 1:
Name: PostComments
Accessible from: All application scopes.
Application: Dependent (x_xyz_dependent)
var PostRComments = Class.create();
PostComments.prototype = {
initialize: function() {},
addComments: function(request, response) {
var requestBody = request.body.dataString;
var parsedData = JSON.parse(requestBody);
var SessionID = parsedData.sessionId;
var responseBody = {};
var AuthToken = parsedData.authToken;
var uName = parsedData.userName;
var uEmail = parsedData.userEmail;
var uAcctID = parsedData.accountID;
var uRegion = parsedData.userRegion;
if (SessionID == "TestSession") {
if (SessionID) {
var appConfigs = {
"ITSM": {
prefix: "x_xyz_itsm.",
tokenProp: "x_xyz_itsm.authToken"
},
"CSM": {
prefix: "x_xyz_csm.",
tokenProp: "x_xyz_csm.authToken"
},
"FSM": {
prefix: "x_xyz_fsm.",
tokenProp: "x_xyz_fsm.authToken"
}
};
var results = [];
var payload = {
uuName: uName,
uuEmail: uEmail,
uuAcctID: uAcctID,
uuRegion: uRegion
};
for (var app in appConfigs) {
var cfg = appConfigs[app];
var existingToken = gs.getProperty(cfg.tokenProp);
if (existingToken && existingToken == AuthToken) {
if (app === "FSM") {
var updater = new x_xyz_fsm.FSMPropertyUpdater();
var updateResult1 = updater.update(payload);
} else if (app === "CSM") {
var updater = new x_xyz_csm.CSMPropertyUpdater();
var updateResult2 = updater.update(payload);
} else if (app === "ITSM") {
var updater = new x_xyz_itsm.ITSMPropertyUpdater();
var updateResult = updater.update(payload);
}
results.push({
application: app,
status: "updated",
matchedToken: true
});
} else {
results.push({
application: app,
status: "skipped - auth token mismatch",
matchedToken: false
});
}
}
var updatedApps = [];
var skippedApps = [];
results.forEach(function(r) {
if (r.matchedToken)
updatedApps.push(r.application);
else
skippedApps.push(r.application);
});
if (updatedApps.length === 0) {
responseBody.status = "Failure";
responseBody.message = "Test Connection - SNOW operation failed. All apps skipped (Auth Token mismatch): " +
skippedApps.join(", ");
} else {
// Normal success scenario
responseBody.status = "Success";
responseBody.message = "Test Connection - SNOW Operation performed successfully";
if (updatedApps.length > 0)
responseBody.message += ". Updated apps: " + updatedApps.join(", ");
if (skippedApps.length > 0)
responseBody.message += ". Skipped apps (auth token mismatch): " + skippedApps.join(", ");
}
}
return JSON.stringify(responseBody);
}
},
type: 'PostComments'
};
Then we have other three Script Includes to update system property present in their respective scope:
Script Include :
Name: ITSMPropertyUpdater
Accessible from: All application scopes.
Application: ITSM (x_xyz_itsm)
var ITSMPropertyUpdater = Class.create();
ITSMPropertyUpdater.prototype = {
initialize: function () {},
update: function (payload) {
gs.info('ITSM SI');
gs.setProperty('x_xyz_itsm.name', payload.uuName);
gs.setProperty('x_xyz_itsm.email', payload.uuEmail);
gs.setProperty('x_xyz_itsm.accountID', payload.uuAcctID);
gs.setProperty('x_xyz_itsm.region', payload.uuRegion);
return {
status: "Success",
app: "ITSM"
};
},
type: 'ITSMPropertyUpdater'
};Similarly for CSM:
Script Include :
Name: CSMPropertyUpdater
Accessible from: All application scopes.
Application: CSM (x_xyz_csm)
var CSMPropertyUpdater = Class.create();
CSMPropertyUpdater.prototype = {
initialize: function () {},
update: function (payload) {
gs.info('ITSM SI');
gs.setProperty('x_xyz_csm.name', payload.uuName);
gs.setProperty('x_xyz_csm.email', payload.uuEmail);
gs.setProperty('x_xyz_csm.accountID', payload.uuAcctID);
gs.setProperty('x_xyz_csm.region', payload.uuRegion);
return {
status: "Success",
app: "CSM"
};
},
type: 'CSMPropertyUpdater'
};
Similarly for FSM:
Script Include :
Name: FSMPropertyUpdater
Accessible from: All application scopes.
Application: FSM (x_xyz_fsm)
var FSMPropertyUpdater = Class.create();
FSMPropertyUpdater.prototype = {
initialize: function () {},
update: function (payload) {
gs.setProperty('x_xyz_fsm.name', payload.uuName);
gs.setProperty('x_xyz_fsm.email', payload.uuEmail);
gs.setProperty('x_xyz_fsm.accountID', payload.uuAcctID);
gs.setProperty('x_xyz_fsm.region', payload.uuRegion);
return {
status: "Success",
app: "FSM"
};
},
type: 'FSMPropertyUpdater'
};
Please guide where I am making mistake that the system properties are not updating.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Navigate to Cross scope privileges [sys_scope_privilege] // you can check by sys_scope_privilege.list
https://<your instance name>/sys_scope_privilege_list.do
In source scope , type your scoped application name ,
There check Target scope and Target name and Status ( status should be allowed for your Write/Update operation)
For your case check GlideAPI: properties is allowed.
Sample Screen shot: Here From Global scope - UI action , using glide record, if scoped record is updated of the scoped application table , that is allowed.
