web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Run another sync job before running the Product-Item sync in BC-CRM Integration

(0) ShareShare
ReportReport
Posted on by 40

Hi,

I have created a new custom table (Prod Group) in BC which has to sync with Sales CRM.

I have done with Table Mapping, Field Mapping and everything works fine.

The Prod Group table is related to Item table as lookup field.  This is working fine too

Item table with the Prod Group look up field is mapped and synced with Sales CRM.  This is working too.

Now, what I want to achieve is, when the Item table sync is initiated, I want to do the Prod Group to be synced first and then to run the Item table sync.  How to achieve this?

Thanks in advance.

I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    on at

    Hello,

    This does not exist out of the box, so I assume you have to code this via an extension that the new ob queue is triggered to run via a codeunit before items run. Is the Prod Group table populated with new data continuously?

    It does make sense though to have this feature built in for partners when they extend the standard sync solution, so feel tree to raise it via a feature request via https://aka.ms/bcideas .

    Thanks.

  • MSD_BC_User Profile Picture
    40 on at

    Thank you Marco Mels for your response. Currently, I am testing on custom table in BC for a lookup field in Item card and syncing this data to CRM. At the time of creating an item, I create a new prod group as well. In this case, it item does not sync to CRM and gets into the error or skipped queue. So, I thought running the related table sync first before performing the actual item sync might solve this problem.

    In real time, at a rare case this situation may occur. If it gets into the skipped queue,, manually need to resolve this. Same problem occurred in the other tables too. What will be the effective way to handle this situation rather than what i have requested for?

    In case, if i go ahead with my method of running the Prod group sync first, what method needs to be called and at which event subsriber metod?

    Thank you.

  • Suggested answer
    Marco Mels Profile Picture
    on at

    Hello,

    Let me ask around internally and come back to this posting after I received an answer.

    Thanks.

  • Verified answer
    Marco Mels Profile Picture
    on at

    Hello,

    Here is an answer that may help to address the issue.

    For full synchronization, you can use the “Dependency Filter” field for table synchs to wait for each other. However dependency filter is used only with full synchronization because conceptually dependency on reoccurring jobs wouldn’t work:

    Level 1 – Job A – Entity X

    Level 2 – Job B – Entity Y

    Level 3 – Job C – Entity Z

    Assume this scenario and they syncs wait for each other. On CRM you created 3 records for each X, Y, Z. Job A has run, it created a record. Job B is running, it is creating another record. Everything looking good so far, but now assume that you created 3 more records when Job B has  just finished and Job C is starting, Job C will create one record successfully but it would fail for the newly created record. Since reoccurring jobs are not the same tree structure as the metadata (Entity X, Y, Z) but it is rather a circle graph, it conceptually fails.

    Maybe a workaround solution could be to schedule a one time sync Job B after job A is completed, for that you could subscribe this event in codeunit 449 "Job Queue Start Codeunit":

    [IntegrationEvent(false, false)]

    local procedure OnAfterRun(var JobQueueEntry: Record "Job Queue Entry")

    And code something like:

    if JobQueueEntry = JobA then schedule JobB

    if JobQueueEntry = JobB then schedule JobC

    This will minimize the problem, but not fix it completely.

    Hope you are getting other useful hints as well. Best probably is to raise this as a feature request so we can develop a permanent solution.

    Thanks

  • Verified answer
    Greg Enns Profile Picture
    1,106 on at

    2 ideas here....

    First: You might try subscribing to the beginning of the Item-Product sync process and forcing your new mapping to sync at that point. If you do that, then you could just turn off the Job Queue for your new mapping.

    Other idea: There is a "Parent Name" field in the Integration Table Mappings. This might get what you want. I haven't tried it, but it might be worth a shot. Try making the Item-Product mapping a child of your new mapping.

  • MSD_BC_User Profile Picture
    40 on at

    Thankyou so much Marco Mels for your detailed response.  I would try Greg Enns suggestion first and will try yours.

  • MSD_BC_User Profile Picture
    40 on at

    Hi Greg Enns,

    Thanks for your response.  For the 2nd idea you have suggested, I have to create a Sync Job Queue to run for the new table.  Right now, I don't find a way to create one.  If I create the new Job entry, there is no way to point it to the new table mapping that I have created.  Can you please point me out to how to create new Sync Job queue for the custom table through AL extension or from adding new record from Job queue card.  

    If this question is not related to the original question raised, I may create a new post just for this.

    Thanks and warm regards.

  • Suggested answer
    Greg Enns Profile Picture
    1,106 on at

    A CRM Sync Job queue, just needs these 3 things:

    "Object Type to Run" := "Object Type to Run"::Codeunit;

    "Object ID to Run" := CODEUNIT::"Integration Synch. Job Runner";

    "Record ID to process" := IntegrationTableMapping.RECORDID;

  • MSD_BC_User Profile Picture
    40 on at

    Hi Greg,

    Thanks for the code.  Would really be grateful if you can point me where this code has to be used in order to create the Job Queue Entry.  I am a newbie to the AL extension.

    Thanks and regards.

  • MSD_BC_User Profile Picture
    40 on at

    Hi,

    I managed to create the new Sync Job Queue Entry for the custom Integration Table mapping. I am not sure, if this is the correct way to go but the below code worked in creating the custom Job Queue Entry.

    With the Mapping record name, I can find the record and create the sync job queue entry.

    	//---get the IntegrationTable Mapping record with the name.  if the record is found create the Job queue entry	
    		TableMappingRec."Name" := 'VENDOR-VENDOR';
            if TableMappingRec.Find('=') then begin
                Message('About to create Job Queue entry for '   TableMappingRec.Name);
                CreateCustomSyncJobQueueEntry(TableMappingRec);
            end	
    			
    			
    			
    			
    			
    	procedure CreateCustomSyncJobQueueEntry(TableMappingRec: Record "Integration Table Mapping")
        var
            JobQueueEntry: Record "Job Queue Entry";
        begin
    
    
            JobQueueEntry.SetRange("Object Type to Run", JobQueueEntry."Object Type to Run"::Codeunit);
            JobQueueEntry.SetRange("Object ID to Run", Codeunit::"Integration Synch. Job Runner");
            JobQueueEntry.SetRange("Record ID to Process", TableMappingRec.RecordId());
            JobQueueEntry.DeleteTasks();
    
            JobQueueEntry.InitRecurringJob(10);
            JobQueueEntry."Object Type to Run" := JobQueueEntry."Object Type to Run"::Codeunit;
            JobQueueEntry."Object ID to Run" := Codeunit::"Integration Synch. Job Runner";
            JobQueueEntry."Record ID to Process" := TableMappingRec.RecordId();
            JobQueueEntry."Run in User Session" := false;
            JobQueueEntry.Description := 'VENDOR-VENDOR - Custom Sync Job';
            JobQueueEntry."Maximum No. of Attempts to Run" := 10;
            JobQueueEntry.Status := JobQueueEntry.Status::Ready;
            JobQueueEntry."Rerun Delay (sec.)" := 30;
            JobQueueEntry."Inactivity Timeout Period" := 5;
            JobQueueEntry."Recurring Job" := true;
    
    
            JobQueueEntry.Insert(true);
    
        end;
    

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,135

#2
YUN ZHU Profile Picture

YUN ZHU 733 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 612

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans