<?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: FX Currency returning incorrect value in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401858#M58784</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Please create after BR Like below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/144730iC534A05AB1A5C0BB/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;and use below script:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideRecord('fx_currency_instance');
    gr.addQuery('id', current.sys_id);
    gr.addEncodedQuery('field=cost');
    gr.query();

    if (gr.next()) {
        var usd = gr.getValue('reference_amount');
    }
    gs.addInfoMessage(usd);
    current.u_cost_usd = usd;
	current.setWorkflow(false);
	current.update();

})(current, previous);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Anil Lande&lt;/P&gt;</description>
    <pubDate>Wed, 06 Apr 2022 14:27:57 GMT</pubDate>
    <dc:creator>Anil Lande</dc:creator>
    <dc:date>2022-04-06T14:27:57Z</dc:date>
    <item>
      <title>FX Currency returning incorrect value</title>
      <link>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401856#M58782</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;There is a &lt;STRONG&gt;Cost&amp;nbsp;&lt;/STRONG&gt;currency field in the alm_hardware table.&lt;BR /&gt;I created another currency field called &lt;STRONG&gt;Cost (USD).&amp;nbsp;&lt;BR /&gt;&lt;/STRONG&gt;The objective is to display the USD equivalent to this custom field.&lt;/P&gt;
&lt;P&gt;The USD equivalent is taken from the Reference amount field in the fx_currency_instance table.&lt;BR /&gt;I have created a BR that is triggered when the Cost field changes.&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var gr = new GlideRecord('fx_currency_instance');
    gr.addQuery('id', current.sys_id);
    gr.addEncodedQuery('field=cost');
    gr.query();

    if (gr.next()) {
        var usd = gr.getValue('reference_amount');
    }

    gs.addInfoMessage(usd);
    current.u_cost_usd = usd;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The issue is the 'usd' value is not saved to the u_cost_usd field.&lt;BR /&gt;Any idea why the field is not updated?&lt;/P&gt;
&lt;P&gt;Please help!&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 13:43:23 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401856#M58782</guid>
      <dc:creator>ceraulo</dc:creator>
      <dc:date>2022-04-06T13:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: FX Currency returning incorrect value</title>
      <link>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401857#M58783</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I hope you have cerate &lt;STRONG&gt;before&lt;/STRONG&gt; update/insert BR. If not then please change it to &lt;STRONG&gt;before&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;BR /&gt;Anil Lande&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 14:19:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401857#M58783</guid>
      <dc:creator>Anil Lande</dc:creator>
      <dc:date>2022-04-06T14:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: FX Currency returning incorrect value</title>
      <link>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401858#M58784</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Please create after BR Like below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/144730iC534A05AB1A5C0BB/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;and use below script:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideRecord('fx_currency_instance');
    gr.addQuery('id', current.sys_id);
    gr.addEncodedQuery('field=cost');
    gr.query();

    if (gr.next()) {
        var usd = gr.getValue('reference_amount');
    }
    gs.addInfoMessage(usd);
    current.u_cost_usd = usd;
	current.setWorkflow(false);
	current.update();

})(current, previous);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Anil Lande&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 14:27:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401858#M58784</guid>
      <dc:creator>Anil Lande</dc:creator>
      <dc:date>2022-04-06T14:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: FX Currency returning incorrect value</title>
      <link>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401859#M58785</link>
      <description>&lt;P&gt;&lt;SN-MENTION class="sn-mention" table="live_profile" sysid="0f401229db581fc09c9ffb651f961987"&gt;@Anil Lande&lt;/SN-MENTION&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had to use an After BR because when the Cost field is updated, the value that is saved in the Cost (USD) field is the previous value. Is there a reason why this should be a Before BR?&lt;/P&gt;
&lt;P&gt;The missing line in my script was the current.update().&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 08:03:27 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401859#M58785</guid>
      <dc:creator>ceraulo</dc:creator>
      <dc:date>2022-04-07T08:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: FX Currency returning incorrect value</title>
      <link>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401860#M58786</link>
      <description>&lt;P&gt;&lt;SN-MENTION class="sn-mention" table="live_profile" sysid="0f401229db581fc09c9ffb651f961987"&gt;@Anil Lande&lt;/SN-MENTION&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This worked! Thank you.&lt;/P&gt;
&lt;P&gt;A couple of questons though.&lt;/P&gt;
&lt;P&gt;1. Why does it have to be a Before BR?&lt;BR /&gt;2. Why the need to setWorkflow to false?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 08:11:25 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401860#M58786</guid>
      <dc:creator>ceraulo</dc:creator>
      <dc:date>2022-04-07T08:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: FX Currency returning incorrect value</title>
      <link>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401861#M58787</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;1. Why does it have to be a Before BR?&lt;/P&gt;
&lt;P&gt;Ans -&amp;gt; In your case before BR will not work because the value in&amp;nbsp;fx_currency_instance table will be updated after your record is update. And using current.update() in before BR is not good practice, your record may go in recursion and may affect many other functionalities.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;2. Why the need to setWorkflow to false?&lt;/P&gt;
&lt;P&gt;Ans - If you want to update current record in BR then we should use setWorkflow(false) to avoid recursion. setworkflow(false) with update/insert operation will not execute any BR, notifications etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;BR /&gt;Anil Lande&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 08:43:40 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401861#M58787</guid>
      <dc:creator>Anil Lande</dc:creator>
      <dc:date>2022-04-07T08:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: FX Currency returning incorrect value</title>
      <link>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401862#M58788</link>
      <description>&lt;P&gt;Glad to know provided solution worked for you.&lt;/P&gt;
&lt;P&gt;Could you please close this question by marking an appropriate answer correct and other responses as helpful? It will be helpful for other community members to refer correct solution for similar issues in future.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can post more questions if you any other queries and tag me if you need help from me, would be happy to reply on your question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Anil Lande&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 08:48:49 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/fx-currency-returning-incorrect-value/m-p/1401862#M58788</guid>
      <dc:creator>Anil Lande</dc:creator>
      <dc:date>2022-04-07T08:48:49Z</dc:date>
    </item>
  </channel>
</rss>

