cancel
Showing results for 
Search instead for 
Did you mean: 

SAP B1 How to refresh the form with new data after update

shuqair_samer
Explorer
0 Kudos

Hi Experts,

I have a requirements on project management window to do some calculations and change some form values (Planned cost and Actual cost) using DI API on Update event handler, the values are updated successfully on database but are not refreshed in the form until I press "Refresh button".on the toolbar.

How to make form refreshed with new values once updated. or is there an event - which I can handle in code - that happens after Update event completed?

if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD || pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE)
{

//Code that will change planned and cost values

}

// if there is another event that happens after the update is completed, so I can activate the refresh in the toolbar

if (pVal.EventType == <Some event>)

{

Application.SBO_Application.ActivateMenuItem("1304");

}

I have been trying use oform.Update() & oForm.Refresh() and other workarounds with no luck

Thanks for your help.

Accepted Solutions (1)

Accepted Solutions (1)

former_member185682
Active Contributor

Hi Shuqair,

You can use the item_pressed event on ItemEvent with beforeAction property equals false, but you need set some global variable that indicates that your update works correctly. Something like this:

        private bool _updated = false;


        private void Application_FormDataEvent(ref SAPbouiCOM.BusinessObjectInfo BusinessObjectInfo, out bool BubbleEvent)
        {
            BubbleEvent = true;
            if (BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE
                && BusinessObjectInfo.ActionSuccess && !BusinessObjectInfo.BeforeAction)
            {
                //Do your update
                _updated = true;
            }
        }


        private void Application_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)
        {
            BubbleEvent = true;
            if(!pVal.BeforeAction && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED && _updated
                && pVal.ItemUID.Equals("the id of your add/update button"))
            {
                Application.SBO_Application.ActivateMenuItem("1304");
                _updated = false;
            }
        }

Hope it helps.

Kind Regards,

Diego Lother

shuqair_samer
Explorer
0 Kudos

Thanks Lother,

This works fine but regarding using global variables, will it be a problem when multi users access the same addon concurrently?

Regards,

former_member185682
Active Contributor
0 Kudos

Hi Shuqair,

The global variable share your value on the scope of your application. But is not possible that the users use the same instance of one add-on concurrently. When an user log on SAP B1 and starts your add-on a new scope of the add-on will be created for this user, even this user log in a SAP B1 client in a server where there is a lot of other users logged.

Use global variables can be a problem in Web Applications, not in this situation.

Hope it clears.

Kind Regards,

Diego Lother

m_felicella
Participant
0 Kudos

You are the best.

May thank's for solutions

0 Kudos

Hi diegolother ,

I have a requirement, On my UDO I have a button to open Sales Order and once its gets added I want the DocTotal to be visible on my UDO. I am updating it but it reflects when I refresh the screen manually. Is there any way to handle it?

Answers (1)

Answers (1)

former_member183397
Participant
0 Kudos

You tried doing it in the classic style:

if (pVal.EventType == <Some event>)
{ 
    Application.SBO_Application.ActivateMenuItem("1289"); //Previous data record
    Application.SBO_Application.ActivateMenuItem("1288"); //Following data record
}

Regards.

shuqair_samer
Explorer
0 Kudos

Thanks Salazar,

Actually this will not work for sub-project management document since this is build in SAP as a tree, when you open the sub-project, all navigating arrow will be disabled.

Regards,