<?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 Persist state between function calls in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Persist-state-between-function-calls/m-p/1206940#M24632</link>
    <description>&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I need to provide a valid sessionid to an API's endpoint.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Towards this end, I created a function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// script-level variable
Session = null;

// if Session doesn't exist or has expired, generate a new one
GetSession = () as record =&amp;gt;
    if Session=null or DateTimeZone.LocalNow &amp;gt; Session[expires] then 
        () =&amp;gt;
        let
            // get session from API
            Response = Xml.Tables(Web.Contents(...)),
            // transform response
            ...
            // assign data to script-level variable
            Session = [
                expires = DateTimeZone.FromText(data[expires]),
                sessionid = data[sessionid]
            ]
        in
            // return
            Session
    else 
        // use existing 
        Session
;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Unfortunately, the function doesn't work as expected.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;What is the recommended way to save a variable's state?&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jul 2020 15:49:42 GMT</pubDate>
    <dc:creator>craibuc</dc:creator>
    <dc:date>2020-07-07T15:49:42Z</dc:date>
    <item>
      <title>Persist state between function calls</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Persist-state-between-function-calls/m-p/1206940#M24632</link>
      <description>&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I need to provide a valid sessionid to an API's endpoint.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Towards this end, I created a function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// script-level variable
Session = null;

// if Session doesn't exist or has expired, generate a new one
GetSession = () as record =&amp;gt;
    if Session=null or DateTimeZone.LocalNow &amp;gt; Session[expires] then 
        () =&amp;gt;
        let
            // get session from API
            Response = Xml.Tables(Web.Contents(...)),
            // transform response
            ...
            // assign data to script-level variable
            Session = [
                expires = DateTimeZone.FromText(data[expires]),
                sessionid = data[sessionid]
            ]
        in
            // return
            Session
    else 
        // use existing 
        Session
;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Unfortunately, the function doesn't work as expected.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;What is the recommended way to save a variable's state?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 15:49:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Persist-state-between-function-calls/m-p/1206940#M24632</guid>
      <dc:creator>craibuc</dc:creator>
      <dc:date>2020-07-07T15:49:42Z</dc:date>
    </item>
  </channel>
</rss>

