Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //*** Script for creation of SSR autimatically ***
  2. // Author: Grzegorz Chwalek
  3. // Version 1.0 - Create skeleton of mapping blocks and mandatory checks
  4. // Version 1.1 - Create order mapping lines and catalog item with variables. Copy catalog item sys id to mapping line
  5.  
  6. // *********** INPUT DETAILS **********************
  7. // define transaction ID and mandatory fields
  8. var transactionID = 'VOI-0011_RequestResetHardphonePIN';
  9. var mandatoryFields = 'uuidPhonelineService';
  10.  
  11. var allVariables = 'uuidPhonelineService';
  12.  
  13. //************ CALLS ****************************
  14.  
  15. // create mapping block for mandatory check and all mapping lines with mandatory values
  16. var mappingBlock_check = createMappingBlock(transactionID, 'check', 'input_ps', 'mapping');
  17. createMappingLinesCheck(mappingBlock_check, mandatoryFields, transactionID);
  18.  
  19. // create mapping block for mapping values
  20. var mappingBlock_mapping = createMappingBlock(transactionID, 'mapping', 'mapping_ps', 'mapping');
  21. createMappingLine(mappingBlock_mapping, 'next', 'nextMap', '100', transactionID + '_order');
  22.  
  23. // create mapping block for order
  24. var mappingBlock_order = createMappingBlock(transactionID, 'order', 'request_ps', 'mapping');
  25. createMappingLines_Order(mappingBlock_order, allVariables, transactionID);
  26.  
  27. // create mapping blocks for response
  28. var mappingBlock_post = createMappingBlock(transactionID, 'post', 'completing_ps', 'completing');
  29. createMappingLine(mappingBlock_post, 'next', 'nextMap', '100', transactionID + '_response');
  30.  
  31. createMappingBlock(transactionID, 'response', 'response_details_ps', 'completing');
  32.  
  33. // create catalog item
  34. var catItemId = createCatalogItem(transactionID);
  35. createCatalogItemVariables(catItemId, allVariables);
  36.  
  37. //create mapping line pointing to Catalog Item sys_id
  38. createMappingLine(mappingBlock_order, 'catalogItemSysId', 'static', '10', catItemId);
  39.  
  40. //******* FUNCTIONS  *****************************************
  41.  
  42. function createMappingBlock(id, type, paramSet, phase) {
  43.     var gr = new GlideRecord('u_sr_mapping_block');
  44.     gr.initialize();
  45.     gr.u_name = id + '_' + type;
  46.     if(type == 'check' || type == 'post'){
  47.         gr.u_selector = id;
  48.     }
  49.     gr.u_customer = 'Siemens';
  50.     gr.u_output_ps = paramSet;
  51.     gr.u_phase = phase;
  52.  
  53.     gr.insert();
  54.  
  55.     return gr.sys_id.toString();
  56. }
  57.  
  58. function createMappingLinesCheck(mappingBlockID, mandatoryFields, transactionID) {
  59.     var mandatoryTable = mandatoryFields.toString().split(",");
  60.     var order = 0;
  61.     for(var i=0; i<mandatoryTable.length; i++){
  62.         order += 10;
  63.         createMappingLine(mappingBlockID, mandatoryTable[i], 'mandatory', order, '');
  64.     }
  65.  
  66.     createMappingLine(mappingBlockID, 'next', ' nextMap', order + 100, transactionID + '_mapping');
  67.  
  68. }
  69.  
  70. function createMappingLines_Order(mappingBlockID, allFields, transactionID) {
  71.     var itemFields = allFields.toString().split(",");
  72.     var order = 20;
  73.     for(var i=0; i<itemFields.length; i++){
  74.         order += 10;
  75.         createMappingLine(mappingBlockID, itemFields[i], 'copy', order, 'input_ps.' + itemFields[i]);
  76.     }
  77. }
  78.  
  79. function createMappingLine(mappingBlockID, targetParam, lineType, order, value) {
  80.     var line = new GlideRecord('u_sr_mapping_line');
  81.     line.initialize();
  82.     line.u_mapping_block = mappingBlockID;
  83.     line.u_output_parm = targetParam;
  84.     line.u_type = lineType;
  85.     line.u_order = order;
  86.     line.u_active = true;
  87.     line.u_value = value;
  88.  
  89.     line.insert();
  90. }
  91.  
  92.  
  93. function createCatalogItem(transactionID) {
  94.     var cat = new GlideRecord('sc_cat_item');
  95.     cat.initialize();
  96.     cat.name = transactionID;
  97.     cat.use_sc_layout = true;
  98.     cat.active = true;
  99.     cat.workflow = '1e0ecd000ffbb5009850ecd692050ef4'; // global SR generic base
  100.     cat.u_cat_item_id = transactionID;
  101.     cat.short_description = transactionID;
  102.     cat.insert();
  103.  
  104.     return cat.sys_id.toString();
  105. }
  106.  
  107. function createCatalogItemVariables(id, variables) {
  108.     var varTable = variables.toString().split(',');
  109.     var order = 10;
  110.     createVariable(id, 19, order, 'Input values', 'inputValues');
  111.  
  112.     for(var i=0; i<varTable.length; i++){
  113.         order += 10;
  114.         createVariable(id, 6, order, varTable[i], varTable[i]);
  115.     }
  116.  
  117.     createVariable(id, 20, order + 10, '', 'inputEnd');
  118.  
  119. }
  120.  
  121. function createVariable(id, varType, varOrder, varQuestion, varName) {
  122.     var gr = new GlideRecord('item_option_new');
  123.     gr.initialize();
  124.     gr.type = varType;
  125.     gr.cat_item = id;
  126.     gr.active = true;
  127.     gr.display_title = true;
  128.     gr.order = varOrder;
  129.     gr.question_text = varQuestion;
  130.     gr.name = varName;
  131.  
  132.     if(varType == 19) {
  133.         gr.layout = '2across';
  134.     }
  135.     gr.insert();
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement