<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Custom table script field execution inside script include in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/custom-table-script-field-execution-inside-script-include/m-p/2373036#M928088</link>
    <description>&lt;P&gt;I solved it..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In script include, I had the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if (customTable.u_run_custom_script) { //if u_run_custom_script is true
    var evaluator = new GlideScopedEvaluator();
    evaluator.putVariable('current', current); //send current to custom script
    evaluator.putVariable('varForSomeConditions', varForSomeConditions); //send other to current script
    evaluator.evaluateScript(customTable, 'u_custom_script', null); //run script form custom script field
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And in custom script field I wrapped it inside function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function () {
    if (someCondition) {
        current.assignment_group = '[sys_id]'; //assignment group 1
    } else if (someOtherCondition) {
        current.assignment_group = '[sys_id]'; //assignment group 2
    }
})();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Nov 2022 15:07:19 GMT</pubDate>
    <dc:creator>Henri Muldre</dc:creator>
    <dc:date>2022-11-04T15:07:19Z</dc:date>
    <item>
      <title>Custom table script field execution inside script include</title>
      <link>https://www.servicenow.com/community/developer-forum/custom-table-script-field-execution-inside-script-include/m-p/2372091#M927858</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying to get&amp;nbsp;&lt;A title="GlideScopedEvaluator" href="https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/GlideEvaluatorAPI" target="_blank" rel="noopener"&gt;GlideScopedEvaluator()&lt;/A&gt; to work, by injecting script from a custom script field into a script include. However, nothing works, except eval(), which should not be used for obvious reasons.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm trying to do:&lt;/P&gt;&lt;P&gt;1. inbound email action starts processing incoming new email&lt;/P&gt;&lt;P&gt;2. inbound email action script calls script include "XMLhandler":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
    var emailBody = email.body_text;
    if (gs.getProperty('some_sys_property_name').indexOf(email.from) &amp;gt; -1) {
        var handleXml = new XMLhandler(emailBody); // call script include "XMLhandler"
        current.contact_type = 'some_value';
    }
    if (current.contact_type == 'some_value') {
        current.insert();
    }
})(current, event, email, logger, classifier);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. script include glides to custom mapping table, which has a script field called&amp;nbsp;u_custom_script and it should execute this script, &lt;STRONG&gt;as if&lt;/STRONG&gt; it would be part of the script include, which eval() does nicely as per my testing, but&amp;nbsp;GlideScopedEvaluator() fails to do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My script in custom table field&amp;nbsp;u_custom_script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if (someCondition) {
    current.assignment_group = '[sys_id]'; //assignment group 1
} else {
    current.assignment_group = '[sys_id]'; //assignment group 2
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, while creating a ticket, I want the current.assignment_group value to be defined in the custom script field. I'm not interested in passing any variables back to script include and settings these there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is part of the script include "XMLhandler", that I am having issues with (:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var parent = "something";
var customTable = new GlideRecord('u_custom_table');
customTable.addQuery('u_parent', parent);
customTable.query();

while (customTable.next()) {
    // Assign values based on form mappings
    current.assignment_group = customTable.u_assignment_group; //assign default value
    //..had many more, but minified it for the purpose of this example
    
    // Run custom script
    if(customTable.u_run_custom_script){ //if u_run_custom_script is true
        /* //Following  works fine, but uses eval(), which is bad
        var script = customTable.u_custom_script;
        var result = Function("return " + script)();
        eval(script); */

        var evaluator  = new GlideScopedEvaluator();
        evaluator.putVariable('current', current);
        evaluator.evaluateScript(customTable, 'u_custom_script', null);
        //evaluator.getVariable("current", current);
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any tips and tricks, how I can get evaluator to work, so that User A adds custom script into custom table script field, then the script is executed as part of the script include, and in turn inbound email action script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The rest of the solution otherwise works fine, however, not the assignment group custom script part.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2022 08:56:15 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/custom-table-script-field-execution-inside-script-include/m-p/2372091#M927858</guid>
      <dc:creator>Henri Muldre</dc:creator>
      <dc:date>2022-11-04T08:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Custom table script field execution inside script include</title>
      <link>https://www.servicenow.com/community/developer-forum/custom-table-script-field-execution-inside-script-include/m-p/2373036#M928088</link>
      <description>&lt;P&gt;I solved it..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In script include, I had the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if (customTable.u_run_custom_script) { //if u_run_custom_script is true
    var evaluator = new GlideScopedEvaluator();
    evaluator.putVariable('current', current); //send current to custom script
    evaluator.putVariable('varForSomeConditions', varForSomeConditions); //send other to current script
    evaluator.evaluateScript(customTable, 'u_custom_script', null); //run script form custom script field
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And in custom script field I wrapped it inside function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function () {
    if (someCondition) {
        current.assignment_group = '[sys_id]'; //assignment group 1
    } else if (someOtherCondition) {
        current.assignment_group = '[sys_id]'; //assignment group 2
    }
})();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2022 15:07:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/custom-table-script-field-execution-inside-script-include/m-p/2373036#M928088</guid>
      <dc:creator>Henri Muldre</dc:creator>
      <dc:date>2022-11-04T15:07:19Z</dc:date>
    </item>
  </channel>
</rss>

