Set Total Cost/Earnings %/Earnings with script

Am trying to change the values of Total Cost using script where a calculation of TotalCost is done using some UDEF the users have to populate on a sale. To do this, I have tried using setEarning (NSSaleEntity) and let the system do the work. Have tried using the code on both before and after saving sale triggers but nothing is changed.

What might I be doing wrong?

RE: Set Total Cost/Earnings %/Earnings with script

Any idea anyone? I can't get it to work, wondering if it might be a bug or if I am using it the wrong way.

Von: Patrik Larsson 13. Feb 2020

RE: Set Total Cost/Earnings %/Earnings with script

Hi Patrick,

Not sure how your code looks, but this works for me in After save Sale:

#setLanguageLevel 3;

EventData ed = getEventData();
NSSaleAgent agent;
NSSaleEntity entity = agent.GetSaleEntity(ed.getInputValue("SaleEntity.SaleId").toInteger());

Float sumTotalSale = entity.GetAmount();
Float sumTotalCost = sumTotalSale - (1000.00);
Float earningP = (sumTotalCost * 100) / sumTotalSale;
entity.SetEarning(sumTotalCost);
entity.SetEarningPercent(earningP);

agent.SaveSaleEntity(entity);
Von: Michel Krohn-Dale 13. Feb 2020

RE: Set Total Cost/Earnings %/Earnings with script

Hi Michel,

Not sure exactly what I did wrong but your works fine. The only thing is that the earning numbers are not updated visually after it has been saved, have to click on edit again to see the correct numbers (total cost is updated directly when saved).

Von: Patrik Larsson 13. Feb 2020

RE: Set Total Cost/Earnings %/Earnings with script

Hi Patrick,

You can use a refresh of the sale using a searchengine and end up with this:

ed.setNavigateTo("soprotocol:sale.main[refresh=true]");The screen is refreshed to the main sale screen.

Von: Henk Bergevoet 13. Feb 2020

RE: Set Total Cost/Earnings %/Earnings with script

Perfect, thanks!

Von: Patrik Larsson 13. Feb 2020

RE: Set Total Cost/Earnings %/Earnings with script

Hi,

Is it possible to also force refresh of the salearchive? When I refresh the salearchive gets blank in Online, so I need to press the refresh button to be able to see the sales connected to the active project. Is there any solution to that?

I'm trying this now:

EventDate ed;
ed.setNavigateTo("soprotocol:project.salearchive[refresh=true]");

Is there any complete documentation of SoProtocol that I can study? If I don't remember it wrong, I believe that I have seen some more extensive article explaning som soProtocol-examples, but can't find it now.

/Marcus

Von: Marcus Svenningsson 25. Feb 2020

RE: Set Total Cost/Earnings %/Earnings with script

Hi,

When you set [refresh=true] you already specify you want it to refresh. You basically tell it to 'go here and then refresh' when setting NavigateTo like this.

The only documentation I know of is this: 
https://community.superoffice.com/en/technical/documentation/older-versions/documentation-7/admin/customizing-the-application/soprotocol/ 

This, unfortunately, does not say salearchive is a valid sub-mode, but it seems logical enough that it exist (you can see it directly in the browser as well). 
It does on the other hand indicate that the protocol should be something like this:
contact.main.activityarchive 

Without testing this myself I would guess this works: 
ed.setNavigateTo("soprotocol:project.main.salearchive[refresh=true]"); 


//Eivind

Von: Eivind Johan Fasting 25. Feb 2020

RE: Set Total Cost/Earnings %/Earnings with script

Hi,

 I ended up using the following which managed to both update the project view as well as the salesarchive:

ed.setNavigateTo("soprotocol:project.salearchive.flush?project_id=" + currentProjId.toString());

This based on a suggestion in a post from Christian Mogensen as below:

https://community.superoffice.com/en/developer/forum/rooms/topic/superoffice-product-api-group/crm-windows-application/use-double-command-on-soprotocol/

He uses the protocol-prefix "superoffice:" instead as well. I don't know if there is any difference? I suppose both might be registrered SuperOffice-protocols doing the same thing. It might be so that "superoffice:" is a later protocol name chosen to better indicate which application it is connected to than using "soprotocol:" maybe?

It would have been interesting to get an explanation from somebody regarding the difference between using the "x.refresh" vs "[refresh=true]", if there should be any.

 

Von: Marcus Svenningsson 26. Feb 2020