record producer script to utilise script include

mskelly
Giga Contributor

Hi Folks,

I have a large script in a record producer which works but now has grown too big for ServiceNow to parse.

So my idea is to utilise Script includes to move the majority of code to a server side "Script Includes"

Alas my skills do not stretch to this so please could someone give me a hand.

The record producer has lots of checkbox variables and based on what the user selects the RP script need to call out to the Script Include and write the result back to the RP script

So an example of the RP script

  if (producer.ItalyBentel_COEINV =='true' || producer.ItalyBentel_IBMINV =='true'){

  current.description= current.description + '\r\n'+'SGTFSEU_APP_191_WEB';

  current.description= current.description + '\r\n'+'SGTFSEU_APP_AGENZIA_DOGANE';

  current.description= current.description + '\r\n'+'SGTFSEU_APP_ALD';

  current.description= current.description + '\r\n'+'SGTFSEU_APP_AMEX';

  }

So I need move this into Script Includes any ideas?

1 ACCEPTED SOLUTION

mskelly
Giga Contributor

OK I have found the answer



The Script include does this



var updateRP3 = Class.create();


updateRP3.prototype = {


      initialize: function() {},




updatebentel :function(){



  if (producer.ItalyBentel_COEINV =='true' || producer.ItalyBentel_IBMINV =='true'){


  current.description= current.description + '\r\n'+'SGTFSEU_APP_191_WEB';


  current.description= current.description + '\r\n'+'SGTFSEU_APP_AGENZIA_DOGANE';


  current.description= current.description + '\r\n'+'SGTFSEU_APP_ALD';


  current.description= current.description + '\r\n'+'SGTFSEU_APP_AMEX';


  current.insert();


  }




},




      type: 'updateRP3'};




In the RP I have this



var rpbentel =new updateRP3();


rpbentel.updatebentel();




and this works a treat thanks you for your responses                  



Mark


View solution in original post

5 REPLIES 5

amaradiswamy
Kilo Sage

Hi Kelly,



Create a script include



name : updateRP



script:


var updateRP = Class.create();


updateRP.prototype = {


      initialize: function() {


      },


  updateScript : function (producer,current)


  {


  if (producer.ItalyBentel_COEINV =='true' || producer.ItalyBentel_IBMINV =='true'){


  current.description= current.description + '\r\n'+'SGTFSEU_APP_191_WEB';


  current.description= current.description + '\r\n'+'SGTFSEU_APP_AGENZIA_DOGANE';


  current.description= current.description + '\r\n'+'SGTFSEU_APP_ALD';


  current.description= current.description + '\r\n'+'SGTFSEU_APP_AMEX';


  current.insert();


  }


},



      type: 'updateRP'


};



In record producer, you can call script include like below



var scrin = new updateRP().updateScript();



Thanks and regards


Swamy



Thanks andupdateScript


Hi Swamy,


Although nothing is stamped in the resulting ticket I used a gs.log in the script includes to verify this being called and it is.


So something needs addressing in the 'updateRP'



Kind Regards



Mark Kelly


anurag92
Kilo Sage

I guess you can do this by calling the script include like below:



(new ScriptIncludeName()).scriptIncludeFunction(current, gs, 'sys ID of catalog', producer);



Now in script include, inside the function



scriptIncludeFunction: function(current, gs, catalogId, producer) {


        // Get the catalog item and copy the model into the template field on the new record


       



if (producer.ItalyBentel_COEINV =='true' || producer.ItalyBentel_IBMINV =='true'){


  current.description= current.description + '\r\n'+'SGTFSEU_APP_191_WEB';


  current.description= current.description + '\r\n'+'SGTFSEU_APP_AGENZIA_DOGANE';


  current.description= current.description + '\r\n'+'SGTFSEU_APP_ALD';


  current.description= current.description + '\r\n'+'SGTFSEU_APP_AMEX';


current.update();


  }



}



This is the way I have seen the working in OOB version. Let me know if this works.


mskelly
Giga Contributor

Hi Anurag,


Sorry i cannot get this to work either



Kind Regards



Mark Kelly