<?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>topic Re: Issueing transaction and rolling back in service scripts in ThingWorx Developers</title>
    <link>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504520#M2809</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There's no Commit / Rollback ( Transactional ) feature on Server Side Javascript, it's automatically handled by platform.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try throwing a fake exception where you have // throw new Exception(), how to do it: throw "EXCEPTION_TEXT", but don't capture it, let platform capture the exception, this should cause a Rollback by the platform.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 31 Mar 2016 11:27:43 GMT</pubDate>
    <dc:creator>CarlesColl</dc:creator>
    <dc:date>2016-03-31T11:27:43Z</dc:date>
    <item>
      <title>Issueing transaction and rolling back in service scripts</title>
      <link>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504519#M2808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wrote a simple service &lt;SPAN style="font-size: 13.3333px;"&gt;below &lt;/SPAN&gt;to update user information from mashups.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14593991931796974 jive_text_macro" jivemacro_uid="_14593991931796974"&gt;&lt;P&gt;var result;&lt;/P&gt;&lt;P&gt;try{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; // (I want to do) tx = getTransaction();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var user = Users[userName];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.lastName = lastName;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.firstName = firstName;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // throw new Exception(); (A)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.emailAddress = emailAddress;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var param = {description : description};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.SetDescription(param);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // oldGroup -&amp;gt; newGroup&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if((oldGroup &amp;amp;&amp;amp; newGroup) &amp;amp;&amp;amp; (oldGroup != newGroup)){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; param = {member: userName};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Groups[newGroup].AddMember(param);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // throw new Exception(); (B)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Groups[oldGroup].DeleteMember(param);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; // (I want to do) tx.commit();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = "Information is successfully updated.";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; logger.info("Info of " + userName + "is updated.");&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;catch(err){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; // (I want to do) tx.rollback();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = "Failed: " + err.message;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; logger.error(result);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This script actually works, but IF error occurs, on line (A) or (B) &lt;SPAN style="font-size: 13.3333px;"&gt;for example&lt;/SPAN&gt;, ｔｈｅ c&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;onsistency of user data can be broken.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;If I can issue transaction and do Commit or Rollback, this problem will be solved.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are there any way to do this, or alternative ideas to do something like this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;S.Yamabe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2016 04:59:28 GMT</pubDate>
      <guid>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504519#M2808</guid>
      <dc:creator>???-31</dc:creator>
      <dc:date>2016-03-31T04:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Issueing transaction and rolling back in service scripts</title>
      <link>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504520#M2809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There's no Commit / Rollback ( Transactional ) feature on Server Side Javascript, it's automatically handled by platform.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try throwing a fake exception where you have // throw new Exception(), how to do it: throw "EXCEPTION_TEXT", but don't capture it, let platform capture the exception, this should cause a Rollback by the platform.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2016 11:27:43 GMT</pubDate>
      <guid>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504520#M2809</guid>
      <dc:creator>CarlesColl</dc:creator>
      <dc:date>2016-03-31T11:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Issueing transaction and rolling back in service scripts</title>
      <link>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504521#M2810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13.3333px;"&gt;Carles,&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Thank you for your advice.&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;I've modified my script, but still not working...&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14594977666073865 jive_text_macro" jivemacro_uid="_14594977666073865"&gt;&lt;P style="font-size: 13.3333px;"&gt;var result;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;try{&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var user = Users[userName];&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.lastName = lastName;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; null.length; // throws exception&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.firstName = firstName;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.emailAddress = emailAddress;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var param = {description : description};&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.SetDescription(param);&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if((oldGroup &amp;amp;&amp;amp; newGroup) &amp;amp;&amp;amp; (oldGroup != newGroup)){&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; param = {member: userName};&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Groups[newGroup].AddMember(param);&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Groups[oldGroup].DeleteMember(param);&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = "Information is successfully updated.";&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; logger.info("Info of " + userName + "is updated.");&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;}&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;catch(err){&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // throw an uncaught exception for rollback&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw "Failed: " + err.message&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;}&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When running this script, I want to leave any properties unchanged.&lt;/P&gt;&lt;P&gt;However, "lastName" is actually changed and saved...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looking into the log, the exception seems to be caught by Server.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Execution error in service script [UserManageServices UpdateUserInfo] : Failed: Cannot read property "length" from null&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does the script above do exactly what you mean?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;S.Yamabe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Apr 2016 08:14:27 GMT</pubDate>
      <guid>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504521#M2810</guid>
      <dc:creator>???-31</dc:creator>
      <dc:date>2016-04-01T08:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: Issueing transaction and rolling back in service scripts</title>
      <link>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504522#M2811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi S.Yamabe,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well the DataBase get's on an unstable state, as if you restart tomcat you will get previous value &lt;SPAN __jive_emoticon_name="wink" __jive_macro_name="emoticon" class="jive_emote jive_macro" src="https://community.ptc.com/7.0.4.3b79b96/images/emoticons/wink.png"&gt;&lt;/SPAN&gt;, hence the Rollback really happens.. -- Maybe we should open a case for this, to investigate if it --&amp;gt; Scaring.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But by the way, it may not work exactly with users that with Things... A Thing can be Restarted a User not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Carles.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Apr 2016 12:37:33 GMT</pubDate>
      <guid>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504522#M2811</guid>
      <dc:creator>CarlesColl</dc:creator>
      <dc:date>2016-04-01T12:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Issueing transaction and rolling back in service scripts</title>
      <link>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504523#M2812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Carles,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you. Let me confirm what you mean. (because I'm not very good at understanding English.. )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. For my script, it is required for Tomcat to be restarted so that I get the previous value of lastName.&lt;/P&gt;&lt;P&gt;2. If the object entities are "Thing"s, restart is(should be) not required.&lt;/P&gt;&lt;P&gt;3. User entities may not be rollback-able.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are these true?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;S.Yamabe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Apr 2016 00:51:16 GMT</pubDate>
      <guid>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504523#M2812</guid>
      <dc:creator>???-31</dc:creator>
      <dc:date>2016-04-04T00:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Issueing transaction and rolling back in service scripts</title>
      <link>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504524#M2813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Yes&lt;/P&gt;&lt;P&gt;2. I don't really know, tests should be done ( the same thing you did with User but with a Thing )&lt;/P&gt;&lt;P&gt;3. May not yes. Well, in reality when you restart Tomcat it will Rollback, which it's worst, as you are working with an unstable state until you restart...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Apr 2016 11:27:57 GMT</pubDate>
      <guid>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504524#M2813</guid>
      <dc:creator>CarlesColl</dc:creator>
      <dc:date>2016-04-04T11:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: Issueing transaction and rolling back in service scripts</title>
      <link>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504525#M2814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I understood the current "specification".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt; in reality when you restart Tomcat it will Rollback&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know that. But as an online systems, it is fatal that restart is required for each exception.&lt;/P&gt;&lt;P&gt;So I should consider rollback is N/A so far.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And, of course, I also think this is the worse problem, &lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;you are working with an unstable state until you restart...&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, I hope any improvements for these problems for the future.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Apr 2016 00:19:44 GMT</pubDate>
      <guid>https://community.ptc.com/t5/ThingWorx-Developers/Issueing-transaction-and-rolling-back-in-service-scripts/m-p/504525#M2814</guid>
      <dc:creator>???-31</dc:creator>
      <dc:date>2016-04-06T00:19:44Z</dc:date>
    </item>
  </channel>
</rss>

