Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

How to create & replicate data across multiple LE's.

Posted on by

Hi experts,

I have  a requirement of creating new workflow & add new project group in 300 plus legal entities.

I have created the workflow, exported its xml myworkflowxml & also created the project group in 1 entity. Current plan is to login to each & every entity , import the workflow xml & create the project group.

Is there any better way using which i could avoid this gignatic manual effort using which i could import the workflow xml across all entities & have the same project grroup configured across all entities.

Thanks

Mav

  • Mav Profile Picture
    Mav on at
    RE: How to create & replicate data across multiple LE's.

    This will not get resolved by changing workflow properties as that is not the issue.

    Let us consider a workflow which is legal entity specific & now we have exported this workflow xml. This xml has to be imported in all 300 plus entity. Currently we go through tedious process of manually importing this xml to all entities.

    Was wondeirng if there is any code which could help in building utility to move the xml file across all entities via code & save from labarious manual effort. Any suggestion/guidance for that.

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 287,914 Super User on at
    RE: How to create & replicate data across multiple LE's.

    Hi Mav,

    I don't have the coding myself. It was created by a developer of the company I worked for in the past. I'm not hired by them anymore. It has been about 5 years ago. I could only provide the suggestion above to solve it with a customization.

    What workflow is required to be shared? If the base table is a global table, it would be possible to setup one global workflow. If the table is having data per legal entity, then also the workflow should be setup per legal entity.

  • Mav Profile Picture
    Mav on at
    RE: How to create & replicate data across multiple LE's.

    @André Arnaud de Calavon

    Can you please share code for workflow import across multiple entities.

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,417 on at
    RE: How to create & replicate data across multiple LE's.

    Hi Mav,

    These field are displayed based of the following fields in ProjGroup-

    1. Project costs - expense > CostTransCost

    2. Project costs - item > ItemTransCost.

    Setting these fields in your code will set the values on the form.

  • Mav Profile Picture
    Mav on at
    RE: How to create & replicate data across multiple LE's.

    Hi

    Thanks a lot for replying , with below code i was able to get desired result  ,however unable to set the "profit & loss " value for below fields in project group form.

    pastedimage1607396179881v1.png

    Please suggest a fix to set values for these which are basically coming from ProjGroup.costTransCostMethod() & ProjGroup.itemTransCostMethod()

    CUrrent code

    static void myJob(Args _args)
    {
    
        ProjGroup lProjGroup;
        DataArea lDataArea;
        int counterIns;
        ProjLinePropertyId lProjLinePropertyId;
        
       
        while select lDataArea where lDataArea.id != 'Le1' && lDataArea.id !='Le2'  && lDataArea.id != 'Le3' && lDataArea.id !='Le4'
         && lDataArea.id != 'Le5'  && lDataArea.id != 'Le6'  && lDataArea.id != 'Le7'  && lDataArea.id != 'Le8'  && lDataArea.id !='Le9'  // Any better way to exclude companies, at time i need to exclude 30  companies.
         
        {
            changeCompany(lDataArea.id)
            {
                lProjGroup = null;
    
                if (!ProjGroup::exist('DEV'))
                {
                    ttsBegin;
                    lProjLinePropertyId = ProjLineProperty::find('EXPENSE').LinePropertyId;
                    lProjGroup.ProjGroupID = 'MyProjid'; 
                    lProjGroup.Name = 'My Proj group name';
                    lProjGroup.projType = ProjType::Cost;
                    lProjGroup.LedgerPosting = ProjLedgerPosting::Categories;
                    lProjGroup.ProjLinePropertySearch = ProjLinePropertySearch::Project;
                    ProjLinePropertySetup::updateLinePropertyProj(lProjGroup.ProjGroupId, lProjLinePropertyId, TableGroupAll::GroupId, true);
                    lProjGroup.EmplTransCost = ProjLedgerStatus::Operations;
                    lProjGroup.insert();
    
                    counterIns  ;
                    info (strFmt('Inserted record in %1 company ',lDataArea.id));
                    ttsCommit;
                }
    
            }
    
        }
        info(strFmt("Total %1 records inserted  ",int2str(counterIns)));
    }
    //END of Job

    @Andre Can you please share the x code using which you were able to distibute workflow configurations to multiple enttities.

    Thanks 

    Mav

  • Verified answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 287,914 Super User on at
    RE: How to create & replicate data across multiple LE's.

    Hi Mav,

    I would try the next coding. At least make sure that you clear the lProjGroup variable per dataarea loop. Also fill the ProjGroupID field with the correct value.

    static void myJob(Args _args)
    {
        ProjGroup lProjGroup;
        DataAreaId dataAreaId;
        List entityList = new List(Types::String);
        Enumerator  entityEnumerator;
        int counterIns;
    
        entityList.addEnd("le2");
        entityList.addEnd("le3");
       
    
        entityList.addStart("le1");
    
        entityEnumerator = entityList.getEnumerator();
    
        while (entityEnumerator.moveNext())
        {
    		dataAreaId = entityEnumerator.current();
    		changeCompany(dataAreaId)
    		{
    		    // first clear the lProjGroup variable as it might still have references
    		    // to the data area from the previous loop
    		    lProjGroup = null;
    		    
    			if (!ProjGroup::exist('myProj'))
    			{
                    ttsBegin;
    
                    lProjGroup.ProjGroupID = 'myProj'; // set at least the project group
    			    //other values to be inserted
    			
    				lProjGroup.insert();
    
    				counterIns  ;
    
                    ttsCommit;
    			}
    			else
    			{
                    // do you need statements here?
    			}
    		}
    
        }
        info(strFmt("%1 records inserted ",int2str(counterIns)));
    }

    If you have 300 legal entities, then the number of statements for 'entityList.addEnd' will be quite a lot. Aren't you able to just loop the DataArea table?

    Concerning importing the workflow in 300 legal entities, it would be possible to create x logic to also loop the legal entities and perform the import. I have worked on an implementation where we had to distribute the workflow configurations to over 1500 legal entities. 

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,417 on at
    RE: How to create & replicate data across multiple LE's.

    Hi Mav,

    I don't see the curly braces after changeCompany keyword. Please try this code and check if that works -

    static void myJob(Args _args)
    {
        ProjGroup lProjGroup;
        DataAreaId dataAreaId;
        List entityList = new List(Types::String);
        Enumerator  entityEnumerator;
        int counterIns;
    
        entityList.addEnd("le2");
        entityList.addEnd("le3");
       
    
        entityList.addStart("le1");
    
        entityEnumerator = entityList.getEnumerator();
        ttsBegin;
        while (entityEnumerator.moveNext())
        {
    		dataAreaId = entityEnumerator.current();
    		changeCompany(dataAreaId)
    		{
    			select  lProjGroup where lProjGroup.ProjGroupId == 'DEV' && lProjGroup.dataAreaId == dataAreaId;
    			// if (!ProjGroup::exist('myProj'))  //tried this approach
    			if (!lProjGroup)
    			{
    				//changeCompany(dataAreaId)          //tried this approach
    				//lProjGroup.dataAreaId = dataAreaId;  //tried this approach gives error fiedl must allow assignement
    			   
    			   //my values to be inserted
    			
    				lProjGroup.insert();
    				counterIns  ;
    			}
    			else
    			{
    
    			}
    		}
    
        }
        info(strFmt("%1 records inserted ",int2str(counterIns)));
        ttsCommit;
    
    	pause;
    }

    In case of the line property Id for each project group Id, you can try this code. It will look if there is a default line property set for the project group Id, and will set it otherwise.

    ProjLinePropertySetup::updateLinePropertyProj(_projGroup.ProjGroupId, _projLinePropertyId, TableGroupAll::GroupId, _set);

  • Mav Profile Picture
    Mav on at
    RE: How to create project group & workflows across 300 plus entities.

    Forgot to share my already developed code for automating the process of adding new proj group across 300 plus entities.

    1>The error despite using change company  "Cannot create a record in Project groups (ProjGroup).
    Insert operations are not allowed across companies. Please use changecompany keyword to change the current company before inserting the record."

    and 

    2>How do i set default line property of project group form which is basically coming from projgroup table method ("projLinePropertyId
    ProjGroup.projLinePropertyId()").

    pastedimage1607356823506v1.png

    my current code 

    static void myJob(Args _args)
    {
        ProjGroup lProjGroup;
        DataAreaId dataAreaId;
        List entityList = new List(Types::String);
        Enumerator  entityEnumerator;
        int counterIns;
    
        entityList.addEnd("le2");
        entityList.addEnd("le3");
       
    
        entityList.addStart("le1");
    
        entityEnumerator = entityList.getEnumerator();
        ttsBegin;
        while (entityEnumerator.moveNext())
        {
          dataAreaId = entityEnumerator.current();
          changeCompany(dataAreaId)
          select  lProjGroup where lProjGroup.ProjGroupId == 'DEV' && lProjGroup.dataAreaId == dataAreaId;
           // if (!ProjGroup::exist('myProj'))  //tried this approach
             if (!lProjGroup)
            {
                //changeCompany(dataAreaId)          //tried this approach
                //lProjGroup.dataAreaId = dataAreaId;  //tried this approach gives error fiedl must allow assignement
               
               //my values to be inserted
            
                lProjGroup.insert();
                counterIns  ;
            }
            else
            {
    
            }
    
    
        }
        info(strFmt("%1 records inserted ",int2str(counterIns)));
        ttsCommit;
    
    pause;
    
    }

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,914 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,549 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans