Name
sn_oe_sfs.VACommonProviderAppUtil
Description
No description available
Script
var VACommonProviderAppUtil = Class.create();
VACommonProviderAppUtil.prototype = {
initialize: function(providerId) {
this.providerId = providerId;
this.PROVIDER_TABLE = sn_oe_sfs.VACommonAdapterConstants.TABLES.PROVIDER;
this.PROVIDER_APP = sn_oe_sfs.VACommonAdapterConstants.TABLES.PROVIDER_APPLICATION;
this.PROVIDER_APPLICATION_TABLE = this.PROVIDER_APP.TABLE_NAME;
this.INBOUND_ID = this.PROVIDER_APP.COLUMNS.INBOUND_ID;
this.NAME = this.PROVIDER_APP.COLUMNS.NAME;
this.PROVIDER = this.PROVIDER_APP.COLUMNS.PROVIDER;
this.MESSAGE_AUTH = this.PROVIDER_APP.COLUMNS.MESSAGE_AUTH;
this.SHORT_DESCRIPTION = this.PROVIDER_APP.COLUMNS.SHORT_DESCRIPTION;
},
/**
* Get the sys_id of the sys_cs_provider_application record
* @param {string} tenantId - inbound id to search in sys_cs_provider_application
*/
getProviderApplicationId: function(inboundId) {
if (!inboundId) {
return '';
}
// check if getProviderAppByInboundAndProviderId api with caching exists
if (Object.getOwnPropertyNames(sn_cs.VASystemObject).indexOf("getProviderAppByInboundAndProviderId") < 0) {
return this.getProviderApplicationIdDeprecated(inboundId);
}
var providerApp = sn_cs.VASystemObject.getProviderAppByInboundAndProviderId(inboundId, '');
var providerAppJSON = providerApp ? JSON.parse(providerApp) : null;
return providerAppJSON && providerAppJSON["sysId"] ? providerAppJSON["sysId"] : '';
},
getProviderApplicationIdDeprecated: function(inboundId) {
var gr = new GlideRecord(this.PROVIDER_APPLICATION_TABLE);
gr.addQuery(this.INBOUND_ID, inboundId);
gr.addQuery(this.PROVIDER, this.providerId);
gr.query();
if (gr.next()) {
return gr.getUniqueValue();
}
return '';
},
/**
* Gets the sys_cs_provider_application record details corresponding to the tenantId
* @param {string} tenantId
*/
getProviderApplicationDetails: function(inboundId) {
if (!inboundId) {
return {};
}
// check if getProviderAppByInboundAndProviderId api with caching exists
if (Object.getOwnPropertyNames(sn_cs.VASystemObject).indexOf("getProviderAppByInboundAndProviderId") < 0) {
return this.getProviderApplicationDetailsDeprecated(inboundId);
}
var providerApp = {};
var providerAppRecord = sn_cs.VASystemObject.getProviderAppByInboundAndProviderId(inboundId, '');
var providerAppJSON = providerAppRecord ? JSON.parse(providerAppRecord) : '';
providerApp[this.INBOUND_ID] = providerAppJSON["inboundId"] ? providerAppJSON["inboundId"] : '';
providerApp[this.PROVIDER] = providerAppJSON["providerId"] ? providerAppJSON["providerId"] : '';
providerApp[this.NAME] = providerAppJSON["name"] ? providerAppJSON["name"] : '';
providerApp[this.MESSAGE_AUTH] = providerAppJSON["messageAuth"] ? providerAppJSON["messageAuth"] : '';
providerApp[this.SHORT_DESCRIPTION] = providerAppJSON["shortDescription"] ? providerAppJSON["shortDescription"] : '';
return providerApp;
},
getProviderApplicationDetailsDeprecated: function(inboundId) {
var providerApp = {};
if (inboundId) {
var gr = new GlideRecord(this.PROVIDER_APPLICATION_TABLE);
gr.addQuery(this.INBOUND_ID, inboundId);
gr.addQuery(this.PROVIDER, this.providerId);
gr.query();
if (gr.next()) {
providerApp[this.INBOUND_ID] = gr.getValue(this.INBOUND_ID);
providerApp[this.PROVIDER] = gr.getValue(this.PROVIDER);
providerApp[this.NAME] = gr.getValue(this.NAME);
providerApp[this.MESSAGE_AUTH] = gr.getValue(this.MESSAGE_AUTH);
providerApp[this.SHORT_DESCRIPTION] = gr.getValue(this.SHORT_DESCRIPTION);
}
}
return providerApp;
},
/**
* Insert a record in sys_cs_provider_application.
* @param {object} providerApp - Key, value pairs matching the column names
*/
insertProviderApplication: function(providerApp) {
// if inbound_id or provider or message_auth is empty, then do not insert
if (!providerApp[this.INBOUND_ID] || !providerApp[this.MESSAGE_AUTH]) {
return '';
}
// insert a record in provider application
var gr = new GlideRecordSecure(this.PROVIDER_APPLICATION_TABLE);
gr.initialize();
gr.setValue(this.INBOUND_ID, providerApp[this.INBOUND_ID]);
gr.setValue(this.PROVIDER, this.providerId);
gr.setValue(this.NAME, providerApp[this.NAME]);
gr.setValue(this.MESSAGE_AUTH, providerApp[this.MESSAGE_AUTH]);
if (providerApp[this.SHORT_DESCRIPTION]) {
gr.setValue(this.SHORT_DESCRIPTION, providerApp[this.SHORT_DESCRIPTION]);
}
return gr.insert();
},
/**
* Update a record in sys_cs_provider_application.
*
* @param {string} providerApplicationId - sys_id of the record to update
* @param {object} providerApp - Key, value pairs matching the column names
*/
updateProviderApplication: function(providerApplicationId, providerApp) {
if (!providerApplicationId || !providerApp['inbound_id'] || !providerApp['message_auth']) {
return '';
}
var gr = new GlideRecordSecure(this.PROVIDER_APPLICATION_TABLE);
if (providerApplicationId && gr.get(providerApplicationId)) {
// if a record is present, then update it
gr.setValue(this.INBOUND_ID, providerApp[this.INBOUND_ID]);
gr.setValue(this.PROVIDER, this.providerId);
gr.setValue(this.NAME, providerApp[this.NAME]);
gr.setValue(this.MESSAGE_AUTH, providerApp[this.MESSAGE_AUTH]);
if (providerApp[this.SHORT_DESCRIPTION]) {
gr.setValue(this.SHORT_DESCRIPTION, providerApp[this.SHORT_DESCRIPTION]);
}
return gr.update() ? gr.getUniqueValue() : '';
}
},
/**
* Deletes a record in sys_cs_provider_application with the sys_id
* @param {string} providerAppId
*/
deleteProviderApp: function(providerApplicationId) {
var gr = new GlideRecordSecure(this.PROVIDER_APPLICATION_TABLE);
if (providerApplicationId && gr.get(providerApplicationId)) {
// if a record is present, then delete it
return gr.deleteRecord();
}
return false;
},
// check if a provider channel is present
isProviderPresent: function() {
// check if getProviderById api with caching exists
if (Object.getOwnPropertyNames(sn_cs.VASystemObject).indexOf("getProviderById") < 0) {
return this.isProviderPresentDeprecated();
}
return sn_cs.VASystemObject.getProviderById(this.providerId);
},
isProviderPresentDeprecated: function() {
return new GlideRecord(this.PROVIDER_TABLE).get(this.providerId);
},
type: 'VACommonProviderAppUtil'
};
Sys ID
67099b66533201101c1addeeff7b123d