Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created an example project on how to use PowerFx in Dynamics 365 Finance and Operations #53

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Samples/Dynamics365FODemo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
**/.vs
**/obj
**/bin/*
**/Resources
**/XppMetadata
**/Reports
**/references

BuildModelResult.log
BuildModelResult.xml
BuildModelResult.err.xml
BuildProjectResult.log
BuildProjectResult.xml
BuildProjectResult.err.xml
CompileLabels.xml
Binary file not shown.
36 changes: 36 additions & 0 deletions Samples/Dynamics365FODemo/Dynamics365FODemo.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.34031.81
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PowerFxDemoLibrary", "PowerFxDemoLibrary\PowerFxDemoLibrary.csproj", "{7BACE988-ECCE-4A1A-AF7F-2A400BBF9601}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7DEDF1AD-DD13-4127-8EEC-12B9E30A7B9D}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
EndProjectSection
EndProject
Project("{FC65038C-1B2F-41E1-A629-BED71D161FFF}") = "PowerFxDemo D365FO (VAR) [PowerFx D365FO Demo]", "PowerFxDemo D365FO\PowerFxDemo D365FO.rnrproj", "{3877D19E-04BE-4209-BFB9-979C95B574BC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7BACE988-ECCE-4A1A-AF7F-2A400BBF9601}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BACE988-ECCE-4A1A-AF7F-2A400BBF9601}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BACE988-ECCE-4A1A-AF7F-2A400BBF9601}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BACE988-ECCE-4A1A-AF7F-2A400BBF9601}.Release|Any CPU.Build.0 = Release|Any CPU
{3877D19E-04BE-4209-BFB9-979C95B574BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3877D19E-04BE-4209-BFB9-979C95B574BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3877D19E-04BE-4209-BFB9-979C95B574BC}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{3877D19E-04BE-4209-BFB9-979C95B574BC}.Release|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {914DB8F6-2C93-420B-9F34-90AF1B21D442}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<AxModelInfo xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<AppliedUpdates xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<Customization>Allow</Customization>
<Description>PowerFx D365FO Demo</Description>
<DisplayName>PowerFx D365FO Demo</DisplayName>
<Id>896000516</Id>
<InternalsVisibleTo xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<Layer>10</Layer>
<Locked>false</Locked>
<ModelModule>PowerFxDemo</ModelModule>
<ModelReferences xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
i:nil="true" />
<ModuleReferences xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d2p1:string>ApplicationFoundation</d2p1:string>
<d2p1:string>ApplicationPlatform</d2p1:string>
<d2p1:string>ApplicationSuite</d2p1:string>
<d2p1:string>ContactPerson</d2p1:string>
<d2p1:string>Directory</d2p1:string>
<d2p1:string>FiscalBooks</d2p1:string>
<d2p1:string>Ledger</d2p1:string>
<d2p1:string>Retail</d2p1:string>
<d2p1:string>SourceDocumentation</d2p1:string>
<d2p1:string>SourceDocumentationTypes</d2p1:string>
<d2p1:string>Tax</d2p1:string>
</ModuleReferences>
<Name>PowerFxDemo</Name>
<Publisher>Dominik Downarowicz</Publisher>
<SolutionId>00000000-0000-0000-0000-000000000000</SolutionId>
<VersionBuild>0</VersionBuild>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<VersionRevision>0</VersionRevision>
</AxModelInfo>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<AxClass xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Name>PowerFxDeliveryAddressContract</Name>
<SourceCode>
<Declaration><![CDATA[
[DataContractAttribute]
class PowerFxDeliveryAddressContract
{
str name;
str street;
str city;
str zipCode;
str countryCode;

}
]]></Declaration>
<Methods>
<Method>
<Name>parmName</Name>
<Source><![CDATA[
[DataMemberAttribute('AddressName')]
public str parmName(str _AddressName = name)
{
name = _AddressName;
return name;
}

]]></Source>
</Method>
<Method>
<Name>parmStreet</Name>
<Source><![CDATA[
[DataMemberAttribute('Street')]
public str parmStreet(str _Street = street)
{
street = _Street;
return street;
}

]]></Source>
</Method>
<Method>
<Name>parmCity</Name>
<Source><![CDATA[
[DataMemberAttribute('City')]
public str parmCity(str _City = city)
{
city = _City;
return city;
}

]]></Source>
</Method>
<Method>
<Name>parmZipCode</Name>
<Source><![CDATA[
[DataMemberAttribute('PostCode')]
public str parmZipCode(str _ZipCode = zipCode)
{
zipCode = _ZipCode;
return zipCode;
}

]]></Source>
</Method>
<Method>
<Name>parmCountryCode</Name>
<Source><![CDATA[
[DataMemberAttribute('ISOCountry')]
public str parmCountryCode(str _CountryCode = countryCode)
{
countryCode = _CountryCode;
return countryCode;
}

]]></Source>
</Method>
<Method>
<Name>getInstance</Name>
<Source><![CDATA[
public static PowerFxDeliveryAddressContract getInstance(LogisticsPostalAddress _postalAddress)
{
PowerFxDeliveryAddressContract deliveryAddress = new PowerFxDeliveryAddressContract();
deliveryAddress.parmName(_postalAddress.Address);
deliveryAddress.parmStreet(_postalAddress.Street);
deliveryAddress.parmCity(_postalAddress.City);
deliveryAddress.parmZipCode(_postalAddress.ZipCode);
deliveryAddress.parmCountryCode(_postalAddress.CountryRegionId);
return deliveryAddress;
}

]]></Source>
</Method>
</Methods>
</SourceCode>
</AxClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<AxClass xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Name>PowerFxDemoRunnable</Name>
<SourceCode>
<Declaration><![CDATA[
using PowerFxDemoLibrary;

internal final class PowerFxDemoRunnable
{
Dialog dialog;
DialogField contextField, formulaField, evaluationField, errorField, salesOrderLookup;

Evaluation evaluator = new Evaluation();
}
]]></Declaration>
<Methods>
<Method>
<Name>main</Name>
<Source><![CDATA[
public static void main(Args _args)
{
new PowerFxDemoRunnable().run();
}

]]></Source>
</Method>
<Method>
<Name>run</Name>
<Source><![CDATA[
public void run()
{
dialog = new Dialog("PowerFX Test");
dialog.form().design().dialogSize(DialogSize::Large);
dialog.addText("Test the new PowerFx engine");

salesOrderLookup = dialog.addField(extendedTypeStr(SalesId), "Select sales order context");

contextField = dialog.addField(extendedTypeStr(WebText), "Context");
contextField.multiLine(true);
contextField.enabled(false);

formulaField = dialog.addField(extendedTypeStr(WebText), "Formula");
formulaField.multiLine(true);
evaluationField = dialog.addField(extendedTypeStr(WebText), "Evaluation Result");
evaluationField.multiLine(true);
errorField = dialog.addField(extendedTypeStr(WebText), "Error");
errorField.multiLine(true);
errorField.enabled(false);

formulaField.registerOverrideMethod(methodStr(FormStringControl, modified), methodStr(PowerFxDemoRunnable, modifiedFormula), this);
salesOrderLookup.registerOverrideMethod(methodStr(FormStringControl, modified), methodStr(PowerFxDemoRunnable, modifiedSalesOrderSelection), this);

dialog.run();
if(dialog.closedOk())
{
Info(evaluationField.value());
}

}

]]></Source>
</Method>
<Method>
<Name>modifiedSalesOrderSelection</Name>
<Source><![CDATA[
public boolean modifiedSalesOrderSelection(FormStringControl _control)
{
if(salesOrderLookup.value()){
PowerFxSalesHeaderContract contract = PowerFxSalesHeaderContract::getInstance(SalesTable::find(salesOrderLookup.value()));
contextField.value(FormJsonSerializer::serializeClass(contract));
}
return true;
}

]]></Source>
</Method>
<Method>
<Name>modifiedFormula</Name>
<Source><![CDATA[
public boolean modifiedFormula(FormStringControl _control)
{
Evaluation.Response response = evaluator.EvaluateInput(contextField.value(), formulaField.value());

if(response.errorThrown == true){
//Split string
List errorList = new List(Types::String);
errorList=strSplit(response.error,'\n');
ListIterator iterator = new ListIterator(errorList);
while(iterator.more())
{
if(iterator.value() != "")
{
Global::error(iterator.value());
}
iterator.next();
}
}
evaluationField.value(response.output);
errorField.value(response.error);
return true;
}

]]></Source>
</Method>
</Methods>
</SourceCode>
</AxClass>
Loading