<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hafsa Fareed Siddiqui on Medium]]></title>
        <description><![CDATA[Stories by Hafsa Fareed Siddiqui on Medium]]></description>
        <link>https://medium.com/@hafsa.fareed21?source=rss-c233ab91c14a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GQ5D_IrgmTbrCfHJ</url>
            <title>Stories by Hafsa Fareed Siddiqui on Medium</title>
            <link>https://medium.com/@hafsa.fareed21?source=rss-c233ab91c14a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 09:18:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hafsa.fareed21/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Role-Based Field Visibility in D365FO Using X++]]></title>
            <link>https://medium.com/@hafsa.fareed21/role-based-field-visibility-in-d365fo-using-x-732a8f0a4fa5?source=rss-c233ab91c14a------2</link>
            <guid isPermaLink="false">https://medium.com/p/732a8f0a4fa5</guid>
            <dc:creator><![CDATA[Hafsa Fareed Siddiqui]]></dc:creator>
            <pubDate>Mon, 03 Feb 2025 12:39:44 GMT</pubDate>
            <atom:updated>2025-02-03T12:39:44.671Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In <strong>Microsoft Dynamics 365 Finance and Operations (D365FO)</strong>, managing <strong>sensitive financial data</strong> is crucial. Not all users should have access to these fields, and controlling field visibility based on <strong>security roles</strong> ensures <strong>data security, compliance, and a better user experience</strong>.</p><p>In this blog post, we’ll explore an <strong>X++ solution</strong> that dynamically <strong>shows or hides fields</strong> in the <strong>SalesTable</strong> and <strong>SalesLine</strong> based on the logged-in user’s role.</p><p>This approach enhances <strong>D365FO security, customization, and user experience</strong>, ensuring that only authorized users can view financial data.</p><h3>Step-by-Step Explanation of the X++ Code</h3><h3>1. Declare Security Role Variables</h3><pre>SecurityRole        securityRole;  <br>SecurityUserRole    securityUserRole;</pre><ul><li>SecurityRole: Represents the security roles defined in D365FO.</li><li>SecurityUserRole: Links users to their assigned security roles.</li></ul><p>This allows us to check whether a user has the necessary permissions.</p><h3><strong>2. Access the Form and Data Sources</strong></h3><ul><li><strong>formRun</strong> captures the current form instance.</li><li><strong>salesTable_ds</strong> accesses the <strong>SalesTable</strong> data source.</li><li><strong>salesLine_ds</strong> accesses the <strong>SalesLine</strong> data source.</li></ul><p>This enables us to modify the visibility of fields dynamically.</p><h3><strong>3. Check the User’s Security Role</strong></h3><p><strong>curUserId()</strong> retrieves the currently logged-in user&#39;s ID.</p><p>The <strong>exists join</strong> ensures that the user&#39;s role exists in the SecurityUserRole table.</p><pre>SecurityRole        securityRole;<br>SecurityUserRole    securityUserRole;<br><br>FormRun         formRun         = sender as FormRun;<br>FormDataSource  salesTable_ds   = formRun.dataSource(formDataSourceStr(SalesTable, salesTable));<br>FormDataSource  salesLine_ds    = formRun.dataSource(formDataSourceStr(SalesTable, Salesline));<br><br>select firstonly Name from securityRole<br>    exists join securityUserRole<br>    where securityRole.RecId == securityUserRole.SecurityRole<br>    &amp;&amp; securityUserRole.User == curUserId()<br>    &amp;&amp; (securityRole.Name == &quot;Your Role Name&quot; ||<br>    securityRole.Name == &quot;Current User&quot;);<br><br>if(securityRole)<br>{<br>    salesTable_ds.object(fieldNum(SalesTable, VSDMarginPercent)).visible(true);<br>}<br>else<br>{<br>    salesTable_ds.object(fieldNum(SalesTable, VSDMarginPercent)).visible(false);<br>}</pre><h3>Benefits of Role-Based Field Visibility in D365FO</h3><p>✅ <strong>Enhanced Security</strong> — Protects sensitive financial data from unauthorized access.<br>✅ <strong>Better User Experience</strong> — Hides unnecessary fields, making the UI cleaner.<br>✅ <strong>Compliance &amp; Governance</strong> — Ensures only designated roles have access to critical information.<br>✅ <strong>Customizable &amp; Scalable</strong> — Easily modify roles or add new security layers as needed.</p><h3>Conclusion</h3><p><strong>Implementing role-based field visibility in D365FO using X++</strong> is a <strong>simple yet effective way</strong> to <strong>enhance data security and user experience</strong>. By dynamically controlling field visibility, businesses can ensure that only authorized users can view or edit sensitive financial data.</p><p>🚀 <strong>Secure your D365FO environment today by implementing this X++ customization!</strong></p><p>👉 <strong>Have questions or need help with D365FO customizations? Drop a comment below!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=732a8f0a4fa5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get Tax Rate and Tax Value from each line(Purchline/Salesline)]]></title>
            <link>https://medium.com/@hafsa.fareed21/get-tax-rate-and-tax-value-from-each-line-purchline-salesline-4e9032667e91?source=rss-c233ab91c14a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e9032667e91</guid>
            <dc:creator><![CDATA[Hafsa Fareed Siddiqui]]></dc:creator>
            <pubDate>Mon, 02 Sep 2024 08:45:04 GMT</pubDate>
            <atom:updated>2024-09-02T08:59:12.587Z</atom:updated>
            <content:encoded><![CDATA[<p>When working with ERP (Enterprise Resource Planning) systems, one of the key functionalities is accurately calculating taxes for various transactions, such as purchases and sales. In Microsoft Dynamics AX or Dynamics 365 for Finance and Operations, this involves retrieving tax rates and values based on specific transaction data.</p><p>This sample function, getTaxRate, retrieves the tax rate for a specific inventory transaction (InventTransId).</p><pre> private TaxValue getTaxRate(InventTransId _inventTransId)<br>    {<br>        TaxGroupData    taxGroupData ;<br>        TaxOnItem       taxOnItem;<br>        TaxData         taxData;<br>  <br>       PurchLine purchLine =  PurchLine::findInventTransId(_inventTransId);<br>  <br>        select firstonly TaxCode from taxGroupData<br>         index hint TaxGroupIdx<br>         where taxGroupData.TaxGroup == purchLine.taxGroup<br>         join taxOnItem<br>         where taxOnItem.TaxItemGroup == purchLine.TaxItemGroup &amp;&amp;<br>         taxOnItem.TaxCode  == taxGroupData.TaxCode<br>         join TaxValue from taxData where taxData.TaxCode == taxGroupData.TaxCode;<br>  <br>        return taxData.TaxValue;<br>    }</pre><p><strong>Fetch the Tax Rate and Tax Value</strong>:</p><ul><li><strong>Tax Rate</strong>: Determined by the TaxGroup and TaxItemGroup associated with the transaction line.</li><li><strong>Tax Value</strong>: Retrieved from the TaxData table based on the matching TaxCode.</li></ul><p>By following these steps, you can accurately obtain the tax rate and tax value for each line item.</p><p>Keywords: Get tax rate, tax value, D365FO, Microsoft Dynamics 365, PurchLine, SalesLine, tax calculation, X++, calculate tax value, calculate tax rate</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e9032667e91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Query to Retrieve Enum Values for a Specific Enum Type]]></title>
            <link>https://medium.com/@hafsa.fareed21/sql-query-to-retrieve-enum-values-for-a-specific-enum-type-50d3eb81a526?source=rss-c233ab91c14a------2</link>
            <guid isPermaLink="false">https://medium.com/p/50d3eb81a526</guid>
            <dc:creator><![CDATA[Hafsa Fareed Siddiqui]]></dc:creator>
            <pubDate>Fri, 05 Jul 2024 12:15:06 GMT</pubDate>
            <atom:updated>2024-07-05T12:15:06.493Z</atom:updated>
            <content:encoded><![CDATA[<p>When working with database tables that store enumerations (enums) and their values, it’s common to need to join these tables to get detailed information about specific enums. The query you provided joins two tables, ENUMVALUETABLE and ENUMIDTABLE, and filters for a specific enum type named &#39;DS_DocumentType&#39;.</p><pre>SELECT * from ENUMVALUETABLE<br><br>join ENUMIDTABLE<br><br>on enumid = id<br><br>and ENUMIDTABLE.NAME = &#39;DS_DocumentType&#39;</pre><h3>Explanation:</h3><p><strong>FROM ENUMVALUETABLE</strong>:</p><ul><li>This specifies the primary table from which to select data. ENUMVALUETABLE typically contains the values associated with enums.</li></ul><p><strong>JOIN ENUMIDTABLE</strong>:</p><ul><li>The JOIN operation combines rows from ENUMVALUETABLE with rows from ENUMIDTABLE based on a related column.</li><li>ENUMIDTABLE typically contains the definitions or metadata for enums, including the enum names and their unique identifiers (id).</li></ul><p><strong>ON ENUMVALUETABLE.enumid = ENUMIDTABLE.id</strong>:</p><ul><li>This condition specifies the relationship between the two tables. It matches rows where the enumid from ENUMVALUETABLE is equal to the id in ENUMIDTABLE.</li><li>This allows you to combine information about enum values with their corresponding enum definitions.</li></ul><p><strong>WHERE ENUMIDTABLE.NAME = ‘DS_DocumentType’</strong>:</p><ul><li>This filter restricts the results to only those rows where the NAME in ENUMIDTABLE matches &#39;DS_DocumentType&#39;.</li><li>This is useful for retrieving all enum values that are associated with a specific enum type named &#39;DS_DocumentType&#39;.</li></ul><h3>Summary:</h3><p>This SQL query is essential for fetching related enum data, facilitating the integration and management of enum values in your application. It helps ensure that you get the specific values and metadata for the enums you are interested in, enabling efficient data handling and display.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50d3eb81a526" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PowerShell Script for Renaming and Updating XML Artifacts]]></title>
            <link>https://medium.com/@hafsa.fareed21/powershell-script-for-renaming-and-updating-xml-artifacts-fd47769c82d8?source=rss-c233ab91c14a------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd47769c82d8</guid>
            <dc:creator><![CDATA[Hafsa Fareed Siddiqui]]></dc:creator>
            <pubDate>Fri, 05 Jul 2024 11:59:49 GMT</pubDate>
            <atom:updated>2024-08-02T12:07:14.702Z</atom:updated>
            <content:encoded><![CDATA[<p>In managing and maintaining software projects, you may often need to rename or update files and their contents to reflect changes in project structure or naming conventions. This PowerShell script is designed to automate the process of renaming XML artifacts and updating their internal contents efficiently.</p><h4>Script Breakdown</h4><p>The script performs two primary tasks:</p><ol><li><strong>Renaming Files</strong>: It changes the names of XML files in a specified directory based on certain patterns.</li><li><strong>Updating File Contents</strong>: It modifies specific strings within the files to match the new naming conventions.</li></ol><p><strong>Step-by-Step Explanation</strong></p><p>$filePath specifies the directory where the XML files are located.</p><p>Open Power shell, and locate to C drive, in this case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*zsy5hfYOUa-1V8l1oj73Tw.png" /></figure><pre>#modify the path for your model<br>$filePath = &quot;C:\PackagesLocalDirectory\AP_ApplicationCustomizationSuite\*.xml&quot;</pre><p><strong>Rename Process Each File</strong>:</p><ul><li>Get-ChildItem retrieves all XML files in the directory and its subdirectories.</li><li>ForEach-Object iterates over each file to apply the required changes.</li></ul><pre>Get-ChildItem -File -Recurse | ForEach-Object {<br>   Rename-Item -Path $_.PSPath -NewName $_.Name.replace(&quot;WA_&quot;,&quot;AP_&quot;)<br>   Rename-Item -Path $_.PSPath -NewName $_.Name.replace(&quot;.WACustomizationsSuite&quot;,&quot;AP_ApplicationCustomizationSuite&quot;)<br>}</pre><ul><li>The script constructs a new file name by replacing the specified patterns (WA_ with AP_ and .WACustomizationsSuite with .AP_ApplicationCustomizationSuite).</li><li>Rename-Item renames the file if the new name differs from the original.</li></ul><p><strong>Update File Contents</strong>:</p><pre># Get the files from the folder and iterate using Foreach<br>Get-ChildItem $filePath -Recurse | ForEach-Object {<br>   # Read the file and use replace()<br>   (Get-Content $_).Replace(&#39;WA_&#39;,&#39;AP_&#39;) | Set-Content $_<br>   # For labels<br>   (Get-Content $_).Replace(&#39;@AP_ApplicationCustomizationSuite&#39;,&#39;@WA_CustomizationSuite&#39;) | Set-Content $_<br>}</pre><ul><li>The script reads the contents of the renamed file.</li><li>It replaces all occurrences in label file of WA_ with AP_ and @AP_ApplicationCustomizationSuite with @WA_CustomizationSuite.</li><li>The modified content is then written back to the file.</li></ul><p><strong>Complete Code:</strong></p><pre>#modify the path for your model<br>$filePath = &quot;C:\PackagesLocalDirectory\AP_ApplicationCustomizationSuite\*.xml&quot;<br><br>Get-ChildItem -File -Recurse | ForEach-Object {<br>   Rename-Item -Path $_.PSPath -NewName $_.Name.replace(&quot;WA_&quot;,&quot;AP_&quot;)<br>   Rename-Item -Path $_.PSPath -NewName $_.Name.replace(&quot;.WACustomizationsSuite&quot;,&quot;AP_ApplicationCustomizationSuite&quot;)<br>}<br># Get the files from the folder and iterate using Foreach<br>Get-ChildItem $filePath -Recurse | ForEach-Object {<br>   # Read the file and use replace()<br>   (Get-Content $_).Replace(&#39;WA_&#39;,&#39;AP_&#39;) | Set-Content $_<br>   # For labels<br>   (Get-Content $_).Replace(&#39;@AP_ApplicationCustomizationSuite&#39;,&#39;@WA_CustomizationSuite&#39;) | Set-Content $_<br>}</pre><h3>Why Use This Script?</h3><p>This PowerShell script is a powerful tool for batch-renaming and updating files, especially useful in scenarios where:</p><ul><li>You are transitioning from old to new naming conventions across a large number of files.</li><li>You need to ensure that internal references within the files are also updated to match the new names.</li><li>You want to automate repetitive tasks to save time and minimize human error.</li></ul><p>By integrating such scripts into your workflow, you can significantly improve efficiency and maintain consistency across your project files.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd47769c82d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Shrink DB Logs(Clear DB logs) to free disk space]]></title>
            <link>https://medium.com/@hafsa.fareed21/shrink-db-logs-clear-db-logs-to-free-disk-space-47290f596a56?source=rss-c233ab91c14a------2</link>
            <guid isPermaLink="false">https://medium.com/p/47290f596a56</guid>
            <dc:creator><![CDATA[Hafsa Fareed Siddiqui]]></dc:creator>
            <pubDate>Wed, 24 Apr 2024 08:29:46 GMT</pubDate>
            <atom:updated>2024-04-24T08:29:46.718Z</atom:updated>
            <content:encoded><![CDATA[<p>Connect SQL as Administrator.</p><p>Here are some steps to follow to clear DB logs:</p><ol><li>Go to AxDB &gt; Properties</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*lEUNxAcWz1Vc6Kc8tR75kA.png" /></figure><p>2. In properties, go to Options &gt; Recovery model and select Simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*SHMGSRoukbr0D1bCyEvoxA.png" /></figure><p>3. Then click OK.</p><p>4. Go to AxDB again. The select Tasks &gt; Shrink &gt; Files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*A0WsaZ2AFzvCfSldhr0ESg.png" /></figure><p>5. In Shrink file, select File type as Log.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*PHvboGRReYUlPBxZp_uBIg.png" /></figure><p>6. Then click OK.</p><p>7. Synchronize the Database at the end.</p><p>Your Logs will be cleared and disk space will be free. Clearing logs and freeing up disk space is essential for maintaining system efficiency and ensuring optimal performance.</p><p>By regularly clearing logs and managing disk space, unnecessary clutter and potential performance bottlenecks can be avoided, allowing for smoother operation and improved functionality of the system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47290f596a56" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get records on Form X++ D365FO (Extension of Form X++ D365FO)]]></title>
            <link>https://medium.com/@hafsa.fareed21/get-records-on-form-x-d365fo-extension-of-form-x-d365fo-ad283de6e6c4?source=rss-c233ab91c14a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad283de6e6c4</guid>
            <dc:creator><![CDATA[Hafsa Fareed Siddiqui]]></dc:creator>
            <pubDate>Tue, 15 Aug 2023 12:01:35 GMT</pubDate>
            <atom:updated>2023-08-15T12:01:35.312Z</atom:updated>
            <content:encoded><![CDATA[<p>The provided X++ code is an extension class for a form in D365FO.</p><pre>    public void checkSalesTaxNumber()<br>    {<br>        FormDataSource ProjInvoiceJour_ds;<br>        ProjInvoiceJour projInvoiceJour;<br>        FormRun formRun;<br><br>        formRun             = this as  FormRun;<br>        projInvoiceJour_ds  = formRun.datasource(FormDatasourceStr(ProjInvoiceListPage,ProjInvoiceJour));//get datasource<br>        projInvoiceJour     = ProjInvoiceJour_ds.cursor();//get current record<br>        if(projInvoiceJour.SalesTaxInvNumber == #EmptyString)<br>        {<br>            try<br>            {<br>                ttsbegin;<br>                if(projInvoiceJour.ACCNum == #EmptyString)<br>                {<br>                    projInvoiceJour.SalesTaxInvNumber = &quot;Empty&quot;;<br>                }<br>                else<br>                {<br>                    projInvoiceJour.SalesTaxInvNumber = projInvoiceJour.ACCNum;                                <br>                }<br>                  projInvoiceJour.update();<br>                  ttscommit;<br>                  projInvoiceJour_ds.research(true);<br>                }<br>                catch<br>                {<br>                  throw Global::error(&quot;Error&quot;);            <br>                }<br>            }<br>      }</pre><p>Here’s a breakdown of the code:</p><ol><li>Overriding method of form control.</li><li>To get datasource from a form:</li></ol><p>formRun = this as FormRun;<br>projInvoiceJour_ds = formRun.datasource(FormDatasourceStr(ProjInvoiceListPage,ProjInvoiceJour));//get datasource<br>projInvoiceJour = ProjInvoiceJour_ds.cursor();//get current record</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*ygV9bQQpWJ-zcRS163QxGg.png" /><figcaption>Snapshot of code in X++ of form extension in D365FO</figcaption></figure><p>This is how you can access form and its data sources in D365FO in X++.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad283de6e6c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get records on Form Control X++ D365FO (Extension of Form Control X++ D365FO)]]></title>
            <link>https://medium.com/@hafsa.fareed21/get-records-on-form-control-x-d365fo-extension-of-form-control-x-d365fo-72b3b006fce8?source=rss-c233ab91c14a------2</link>
            <guid isPermaLink="false">https://medium.com/p/72b3b006fce8</guid>
            <dc:creator><![CDATA[Hafsa Fareed Siddiqui]]></dc:creator>
            <pubDate>Tue, 15 Aug 2023 11:25:38 GMT</pubDate>
            <atom:updated>2023-08-15T11:26:04.399Z</atom:updated>
            <content:encoded><![CDATA[<p>The provided X++ code is an extension class for a button control in the CustInvoiceJournal form. It notifies the user when the button is clicked.</p><pre>[ExtensionOf(formControlStr(custinvoicejournal, View))]<br>final class CustInvoiceJournal_PrintButtCtrl_Extension<br>{    <br>        void  clicked()<br>        {<br>            next clicked();<br>              <br>            CustInvoiceJour custInvoiceJour;<br>            FormDataSource      custInvoiceJour_ds;<br>            FormRun             formRun;<br>            FormControl         view;<br><br>            formRun = this.formRun(); <br>            custInvoiceJour_ds = formRun.dataSource(&quot;CustInvoiceJour&quot;);//get datasource<br>            custInvoiceJour = custInvoiceJour_ds.cursor();// current record<br><br>            view = formRun.design(0).controlName(&quot;YourControlName &quot;);//get control<br><br>            if(custInvoiceJour.ACCNumber == &#39;&#39;)<br>            {<br>                checkFailed(&quot;Comment&quot;);<br>            }<br>        }<br>      }</pre><p>Here’s a breakdown of the code:</p><ol><li>Overriding clicked method of form control.</li><li>To get datasource from a form:</li></ol><p>formRun = this.formRun();</p><p>custInvoiceJour_ds = formRun.dataSource(“CustInvoiceJour”);</p><p>custInvoiceJour = custInvoiceJour_ds.cursor();</p><p>3. Access control from form and enable/disable the button: view = formRun.design(0).controlName(“YourControlName”);//accessing form control</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*dKGaro5Oew_1u_Z4Vds0Cw.png" /></figure><p>This is how you can access control on a form in D365FO in X++.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72b3b006fce8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get records on Form DataSource X++ D365FO]]></title>
            <link>https://medium.com/@hafsa.fareed21/get-records-on-form-datasource-x-d365fo-e9139cc48bf9?source=rss-c233ab91c14a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9139cc48bf9</guid>
            <dc:creator><![CDATA[Hafsa Fareed Siddiqui]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 08:34:28 GMT</pubDate>
            <atom:updated>2024-03-12T08:32:57.091Z</atom:updated>
            <content:encoded><![CDATA[<h3>Get records on Form DataSource X++ D365FO (Extension of Form DataSource X++ D365FO)</h3><h3>Chain of Command(COC) Form DataSource</h3><p><strong>The provided X++ code is an extension(COC) for form Data Source.</strong></p><p>This code is an extension class for the SalesTable data source in the SalesTable form. It is used to disables a button on the SalesTable form.</p><pre>[ExtensionOf(formDataSourceStr(SalesTable, SalesTable))]<br>final class SalesTable_Ds_Extension<br>{    <br>        public int active()<br>        {<br>            int ret;<br><br>            ret = next active();<br><br>            SalesTable salesTable = this.cursor(); //current record<br>            <br>            if(salesTable.ACCNumber)<br>            {<br>                element.control(element.controlId(formControlStr(SalesTable,OfferNumber))).enabled(false);<br>            }<br>            else<br>            {<br>                element.control(element.controlId(formControlStr(SalesTable,OfferNumber))).enabled(true);<br>            }<br><br>            return ret;<br>        }<br>}</pre><p><strong>Here’s a breakdown of the code in X++:</strong></p><ol><li>Overriding active method of SalesTable datasource.</li></ol><p><strong>2. To get current record on a form:</strong></p><p>As we are on the SalesTable datasource, we can get the record in a table buffer by:</p><p>SalesTable salesTable = this.cursor(); //current record</p><p><strong>3. Access control from form and enable/disable the button:</strong> element.control(element.controlId(formControlStr(SalesTable,OfferNumber))).enabled(false); //accessing form control</p><h3><strong>We can also access data source like this:</strong></h3><pre>FormDataSource formDataSource;<br>ProjInvoiceJour projInvoiceJour;<br>FormRun formRun;<br><br>formRun = this as FormRun;<br>formDataSource = formRun.datasource(FormDatasourceStr(ProjInvoiceListPage,ProjInvoiceJour)); // get data source<br>projInvoiceJour = formDataSource.cursor(); // current record</pre><p>FormDataSource formDataSource;</p><p>ProjInvoiceJour projInvoiceJour;</p><p>FormRun formRun;</p><p>formRun = this as FormRun;</p><p>formDataSource = formRun.datasource(FormDatasourceStr(ProjInvoiceListPage,ProjInvoiceJour)); // get data source</p><p>projInvoiceJour = formDataSource.cursor(); // current record</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9139cc48bf9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a lookup having multiple values from multiple tables]]></title>
            <link>https://medium.com/@hafsa.fareed21/create-a-lookup-having-multiple-values-from-multiple-tables-203bd38d7d0e?source=rss-c233ab91c14a------2</link>
            <guid isPermaLink="false">https://medium.com/p/203bd38d7d0e</guid>
            <dc:creator><![CDATA[Hafsa Fareed Siddiqui]]></dc:creator>
            <pubDate>Thu, 03 Aug 2023 11:01:09 GMT</pubDate>
            <atom:updated>2023-08-03T11:17:52.378Z</atom:updated>
            <content:encoded><![CDATA[<p>To create a lookup having multiple values from multiple tables.</p><p>Create a view of all the tables that are used.</p><p>For example, you want to show two values in a lookup. BOM Id and VersionId.</p><p>You need to join 3 tables.</p><ol><li>BOMTable</li><li>BOM</li><li>InventDim</li></ol><p>Since there is no direct relation of BOMTable and InventDim, we create a view.</p><figure><img alt="View in Dynamics 365FO" src="https://cdn-images-1.medium.com/max/721/1*NCSN6i3dKRVTnXBIylu4vw.png" /></figure><p>Now, override the lookup method and write a custom lookup code in X++.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*XnkjyzqqBsYL3N57HsRa5g.png" /><figcaption>X++ code for lookup. “YourView” is the View that you will create.</figcaption></figure><p>QueryBuildDataSource qbds,qbdsBOM, qbdsInventDim;</p><p>Query query = new Query();</p><p>SysTableLookup sysTableLookup;</p><p>qbds = query.addDataSource(tableNum(YourView));</p><p>sysTableLookup = SysTableLookup::newParameters(tablenum(YourView), _bomNameLookup);</p><p>SysTableLookup.addLookupfield(fieldNum(YourView, BOMId), true);</p><p>SysTableLookup.addLookupfield(fieldNum(YourView, InventVersionId));</p><p>sysTableLookup.parmQuery(query);</p><p>sysTableLookup.performFormLookup();</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*E-NKjCumdrD_12jmOwxxng.png" /><figcaption>Lookup showing BOMId and Version</figcaption></figure><p>This is how you can create a custom lookup in D365FO in X++ having multiple values from multiple tables. You can add as many fields in the lookup as you wish.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=203bd38d7d0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>