setOutputValue in after saving contact trigger

lock
push_pin
done
Answered
9

Hi

Ever since deployment of configurable screens the function EventData.setOutputValue seems to have no effect in after saving contact (person) and after saving company trigger: the browser displays the state, as if the trigger was not active.
Attempts to refresh browser by using "soprotocol:person" inside the trigger do not work either:

ed.setNavigateTo("soprotocol:person.main[refresh=true]");

The only workaround I found is to manually refresh the browser using F5.

Is there a way to force SuperOffice to refresh the display, from inside a trigger?

Or is the lack of effect of setOutputValue a bug?

Best regards
Marc

13 Jan 2022 | 05:41 PM

All Replies (9)

Hi Marc!

There is some speculation this might be fixed in 10.0.5. Could you verify this using your SOD tenant (which should be on 10.0.5) now.

Best regards.

14 Jan 2022 | 01:22 PM

Hi Tony

unfortunately, 10.0.5 (SOD) exhibts the same behavior as 10.0.4 (production): setOutputValue and setNavigateTo have no effect.

Best regards, Marc 

14 Jan 2022 | 03:56 PM

Hi Marc,
Think we need to split this into two separate problems;

  • setOutputValue - You cannot modify entities in EventData in "AfterSave" events, entity has already been saved. If you want to modify entity you need to use standard API (Agent and Entity classes). You might consider moving your script to "BeforeSave" events to utilize setOutputValue.
  • setNavigateTo - This we need to look into why it is not working as intended.

/Michel

17 Jan 2022 | 08:36 AM

Hi Michel,

my assumption was that setOutputValue should display values in front end (browser). However, it sets values to be saved in the before save trigger. In that respect, it works as designed. If I call setOutputValue in the before save trigger of person, then the database is updated automatically, and the new value is displayed in the browser, as expected and tested in 10.0.5

However, the issue remains, that we cannot refresh the browser from inside an after save trigger. That is, ed.setNavigateTo("soprotocol:person.main[refresh=true]") has no effect there, as tested in 10.0.5

Best regard, Marc

18 Jan 2022 | 11:38 AM
We are still investigating issue with refresh and hopefully we will find a solution for this and correct the behaviour
/Michel
20 Jan 2022 | 12:36 PM

Any update on this? The issue with setOutputValue on after save triggers is still there.

24 Mar 2022 | 07:37 AM

Hi Espen,

As already stated setOutputValue in After Save event is not something supported, please provide more information about what you are trying to accomplish.

/Michel

24 Mar 2022 | 07:50 AM

Hi Michel

Ah, I misunderstood then. Marc's assumption about setOutputValue setting display values in the front end is what I'm talking about. I know it can't be used for actually saving values to the database in after save triggers, but I was working on the same assumption as him, simply because it used to work like how he describes.

I have an example that is related to the after saving sale trigger, but I believe it's the same issue Marc is talking about.

Let's say you want to make a trigger that creates a project connected to the sale, when setting a sale to Sold:

#setLanguageLevel 3;
EventData ed = getEventData();
Integer saleId = ed.getInputValue("SaleEntity.SaleId").toInteger();

if (ed.getInputValue("SaleStatusChanged").toBool() == True && ed.getInputValue("SaleStatus") == "2")
{
  // Create project
  NSProjectAgent projectAgent;
  NSProjectEntity projectEntity = projectAgent.CreateDefaultProjectEntity();

  // Set various project values
  projectEntity.SetName("My own project");
  // ........

  // Save project
  projectEntity = projectAgent.SaveProjectEntity(projectEntity);
  Integer newProjectId = projectEntity.GetProjectId();

  // Connect the new project to sale with NSSaleEntity
  NSSaleAgent saleAgent;
  NSSaleEntity saleEntity = saleAgent.GetSaleEntity(saleId);

  NSProject project;
  project.SetProjectId(newProjectId);
  saleEntity.SetProject(project);
  saleAgent.SaveSaleEntity(saleEntity);

  // ...and also through setOutputValue to make sure it's displayed to the user immediately
  ed.setOutputValue("SaleEntity.Project.ProjectId", newProjectId.toString());
}

You could put this in the Before saving sale trigger, but then it wouldn't work for new sales that you immediately set to Sold, because they don't have a sale ID yet. Therefore I have preferred to to put this in the After saving sale trigger. However, in order to display the project on the sales card immediately after saving without having to refresh, I have used .setOutputValue() as shown in my code.

Not sure if this was just a hacky way to do it and not how the function was really intended, but it used to work. Now it doesn't work like that anymore; The project is not displayed until you refresh the sale.

I guess another way to do is to create the project in Before save sale and then pass the new project ID as a state value to After save...

24 Mar 2022 | 08:43 AM

Hi Espen,

Think we sort of are mixing apples and oranges here. Main issue for Marc was that with configurable screens (Company/Contact) he was not able to properly refresh screen using setNavigateTo(<soprotocol>), in After Save events this is proper way of forcing UI to update to reflect changes done. 
In your scenario this works as expected;

#setLanguageLevel 3;
EventData ed = getEventData();
Integer saleId = ed.getInputValue("SaleEntity.SaleId").toInteger();

if (ed.getInputValue("SaleStatusChanged").toBool() == True && ed.getInputValue("SaleStatus") == "2")
{
  // Create project
  NSProjectAgent projectAgent;
  NSProjectEntity projectEntity = projectAgent.CreateDefaultProjectEntity();

  // Set various project values
  projectEntity.SetName("My own project");
  // ........

  // Save project
  projectEntity = projectAgent.SaveProjectEntity(projectEntity);
  Integer newProjectId = projectEntity.GetProjectId();

  // Connect the new project to sale with NSSaleEntity
  NSSaleAgent saleAgent;
  NSSaleEntity saleEntity = saleAgent.GetSaleEntity(saleId);

  NSProject project;
  project.SetProjectId(newProjectId);
  saleEntity.SetProject(project);
  saleAgent.SaveSaleEntity(saleEntity);

  // ...refresh screen to view changes
  ed.setNavigateTo("soprotocol:sale.main[refresh=true]");
  
  //NOT the way to do it
  //ed.setOutputValue("SaleEntity.Project.ProjectId", newProjectId.toString());
}
24 Mar 2022 | 09:02 AM
Hi Michel
Ah, thanks a lot. That works a lot better. And sorry I was mixing up issues here.
24 Mar 2022 | 09:29 AM

Hi, we're seeing the same issue with setNavigateTo when script is called from a Button in a customized company screen in CRM.

That button calls a CRMScript, and we want to refresh the screen once the button has done its job.

// (Script first does some magic to update company in SuperOffice)

// Then we want to refresh the GUI to show new data
EventData ed = getEventData();
//ed.setNavigateTo("soprotocol:contact.main?contact_id=" + ed.getInputValue("ContactEntity.ContactId"));
//ed.setNavigateTo("soprotocol:contact.main[refresh=true]");
ed.setMessage("Update completed. Press F5 to refresh"); // Workaround

For now we have to tell users to refresh manually, but hopefully your bugfix will fix this scenario as well.

31 Mar 2022 | 09:31 AM
Added as bug 26878.
1 Apr 2022 | 01:13 PM

Add reply