cancel
Showing results for 
Search instead for 
Did you mean: 

CCO Plugin Articles Synchronisation

haythem_jaidi
Participant
0 Kudos

Hi Experts,

I would lile to build a plugin to add an Material in Business One and to trigger the Article Synchronization.

I was able to build the Plugin UI and to consume B1 Service Layer to add the Master Data and I am looking for the right way to trigger the com.sap.scco.ap.pos.job.MaterialJob Synchronization from Backend and to react on the Job Completed Event.

By inspecting the code of CCO UI on Chrome I was able to locate this Ajax call behind the immediate Sync:

$.ajax({
	url: 'SyncDataWithByDServlet',
	data: scheduleSyncData,
	type: 'POST',
	dataType: 'json',
	success: function(data) {
		if ('success' === data.status) {
			$('#notificationArea').notificationStyle('Success', data.description);
			//if the original schedule was an immediate/none sync -> skip this additional sync
			if (instance._interval !== instance._interval_now_code && instance._interval !== instance._interval_none_code) {
				//post data to restore the schedule of the original sync
				instance.repostScheduleData(instance._cleanSync);
			}
		} else {
			$('#notificationArea').errorStyle('Error',
				data.description);
		}
	},
	error: function(xhr, status, error) {
		$('#notificationArea').errorStyle('Error', error);
	}
});

But I think it is not the right way.

So, what is the right way to trigger the Sync of Article from CCO Plugin Backend? And how to react on the Job Complete event?

View Entire Topic
R_Zieschang
Contributor

Hi haythem.jaidi,

I would not do such things on the UI layer. You could try something like:

new JobScheduler().runJobNow("MaterialJob");

This should trigger the material sync.

If you would like to react when the material was synced, there is a PluginExit called "BusinessOneServiceWrapper.fetchMaterials.afterProcessing" which you could use.

HTH
Robert

haythem_jaidi
Participant
0 Kudos

Hi robertzieschang,

Thank you for the answer. This is working!

new JobScheduler().runJobNow("MaterialJob", true);

And The exit:

    @ListenToExit(exitName = PluginExitPoints.BUSINESS_ONE_SERVICE_WRAPPER_AFTER_PROCESSING)
    public PluginExitResult<Map> material(Object calledBy, Object[] args){
        return null;
    }