Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*** Script for creation of SSR autimatically ***
- // Author: Grzegorz Chwalek
- // Version 1.0 - Create skeleton of mapping blocks and mandatory checks
- // Version 1.1 - Create order mapping lines and catalog item with variables. Copy catalog item sys id to mapping line
- // *********** INPUT DETAILS **********************
- // define transaction ID and mandatory fields
- var transactionID = 'VOI-0011_RequestResetHardphonePIN';
- var mandatoryFields = 'uuidPhonelineService';
- var allVariables = 'uuidPhonelineService';
- //************ CALLS ****************************
- // create mapping block for mandatory check and all mapping lines with mandatory values
- var mappingBlock_check = createMappingBlock(transactionID, 'check', 'input_ps', 'mapping');
- createMappingLinesCheck(mappingBlock_check, mandatoryFields, transactionID);
- // create mapping block for mapping values
- var mappingBlock_mapping = createMappingBlock(transactionID, 'mapping', 'mapping_ps', 'mapping');
- createMappingLine(mappingBlock_mapping, 'next', 'nextMap', '100', transactionID + '_order');
- // create mapping block for order
- var mappingBlock_order = createMappingBlock(transactionID, 'order', 'request_ps', 'mapping');
- createMappingLines_Order(mappingBlock_order, allVariables, transactionID);
- // create mapping blocks for response
- var mappingBlock_post = createMappingBlock(transactionID, 'post', 'completing_ps', 'completing');
- createMappingLine(mappingBlock_post, 'next', 'nextMap', '100', transactionID + '_response');
- createMappingBlock(transactionID, 'response', 'response_details_ps', 'completing');
- // create catalog item
- var catItemId = createCatalogItem(transactionID);
- createCatalogItemVariables(catItemId, allVariables);
- //create mapping line pointing to Catalog Item sys_id
- createMappingLine(mappingBlock_order, 'catalogItemSysId', 'static', '10', catItemId);
- //******* FUNCTIONS *****************************************
- function createMappingBlock(id, type, paramSet, phase) {
- var gr = new GlideRecord('u_sr_mapping_block');
- gr.initialize();
- gr.u_name = id + '_' + type;
- if(type == 'check' || type == 'post'){
- gr.u_selector = id;
- }
- gr.u_customer = 'Siemens';
- gr.u_output_ps = paramSet;
- gr.u_phase = phase;
- gr.insert();
- return gr.sys_id.toString();
- }
- function createMappingLinesCheck(mappingBlockID, mandatoryFields, transactionID) {
- var mandatoryTable = mandatoryFields.toString().split(",");
- var order = 0;
- for(var i=0; i<mandatoryTable.length; i++){
- order += 10;
- createMappingLine(mappingBlockID, mandatoryTable[i], 'mandatory', order, '');
- }
- createMappingLine(mappingBlockID, 'next', ' nextMap', order + 100, transactionID + '_mapping');
- }
- function createMappingLines_Order(mappingBlockID, allFields, transactionID) {
- var itemFields = allFields.toString().split(",");
- var order = 20;
- for(var i=0; i<itemFields.length; i++){
- order += 10;
- createMappingLine(mappingBlockID, itemFields[i], 'copy', order, 'input_ps.' + itemFields[i]);
- }
- }
- function createMappingLine(mappingBlockID, targetParam, lineType, order, value) {
- var line = new GlideRecord('u_sr_mapping_line');
- line.initialize();
- line.u_mapping_block = mappingBlockID;
- line.u_output_parm = targetParam;
- line.u_type = lineType;
- line.u_order = order;
- line.u_active = true;
- line.u_value = value;
- line.insert();
- }
- function createCatalogItem(transactionID) {
- var cat = new GlideRecord('sc_cat_item');
- cat.initialize();
- cat.name = transactionID;
- cat.use_sc_layout = true;
- cat.active = true;
- cat.workflow = '1e0ecd000ffbb5009850ecd692050ef4'; // global SR generic base
- cat.u_cat_item_id = transactionID;
- cat.short_description = transactionID;
- cat.insert();
- return cat.sys_id.toString();
- }
- function createCatalogItemVariables(id, variables) {
- var varTable = variables.toString().split(',');
- var order = 10;
- createVariable(id, 19, order, 'Input values', 'inputValues');
- for(var i=0; i<varTable.length; i++){
- order += 10;
- createVariable(id, 6, order, varTable[i], varTable[i]);
- }
- createVariable(id, 20, order + 10, '', 'inputEnd');
- }
- function createVariable(id, varType, varOrder, varQuestion, varName) {
- var gr = new GlideRecord('item_option_new');
- gr.initialize();
- gr.type = varType;
- gr.cat_item = id;
- gr.active = true;
- gr.display_title = true;
- gr.order = varOrder;
- gr.question_text = varQuestion;
- gr.name = varName;
- if(varType == 19) {
- gr.layout = '2across';
- }
- gr.insert();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement