Coming soon: Your brand new Help Center & Community! Get a sneak-peek here

Open contact card in edit mode with WIN script

Anyone got a code for vbscript that will open a contact in edit mode?

SuperOffice 7.5 sr2

Due to the fact you can change the text in for example Orgnr field and then press OK without leaving the field allows a validation check based on the Fieldchanged event

to be bypassed.

Then I need to validate before save and if this validation message isn't empty, to reopen the contact in edit mode forcing the user to correct the error before navigating away.

Tried

SetSoProtocol "superoffice:contact.activityarchive.main.minimonth?contact_id="&currentcontact.identity&"&edit"

but that doesn't work.

Tried context.SetEditmode(true)

but that doesn't work either.

Seems like it sets it to edit mode briefly but then hops back.

RE: Open contact card in edit mode with WIN script

Why don't you trigger your validation on multiple events?

Or make a shadow copy of the field value before the field change, and validate the value before save, resetting it to the original value if invalid?

Af: Jochen Siegenthaler 20. jun 2017

RE: Open contact card in edit mode with WIN script

I already validate on multiple events.

The issue is that when the contact is set in edit mode it passes validation.

Changing the value in a varchar field without leaving the field doesn't trigger any events so the validation occurs too late to prevent propagation to the database.

In this particular case the validation includes that only one of two text fields can contain data and as such I have no way of knowing which was correct.

Af: Jason Tiler Broad 20. jun 2017

RE: Open contact card in edit mode with WIN script

I already validate on multiple events.

The issue is that when the contact is set in edit mode it passes validation.

Changing the value in a varchar field without leaving the field doesn't trigger any events so the validation occurs too late to prevent propagation to the database.

In this particular case the validation includes that only one of two text fields can contain data and as such I have no way of knowing which was correct.

Af: Jason Tiler Broad 20. jun 2017

RE: Open contact card in edit mode with WIN script

You're welcome to try this yourself.

Though I would strongly advise against running it against a live system :-)


SUB OnEditContactComplete()
somessagebox currentcontact.identity
SetSoProtocol "superoffice:contact.activityarchive.main.minimonth?contact_id="&currentcontact.identity&"&edit"
somessagebox CurrentSoProtocol
Setcontext 0,0,0
context.seteditmode(true)
somessagebox context.editmode
End Sub
 
 
Curiously the final message box reports context.editmode=true although the contact card is patently not in edit mode.
Af: Jason Tiler Broad 20. jun 2017

RE: Open contact card in edit mode with WIN script

This is fixed in upcoming 8.1.
The ValidationMessage will be able to intervene the clicking of the Save button and Disable it (via an implicit focus-change that will dispath a field changed message..)
Regards,
Conrad

Af: Conrad Weyns 20. jun 2017

RE: Open contact card in edit mode with WIN script

Hi Conrad,

That it is fixed in 8.1 doesn't help me much today when the customer is on 7.5

An upgrade to 8.1 isn't just around the corner as the customer has several integrations and other scripts that would have to be updated too.

Is there any code that works in 7.5 win script that will open a contact in edit mode?

Or am I going to have to make a longwinded workaround that caches the values in both fields before editing and reset them  if validation is failed? (Please no!!)

Even though context.editmode returns true it is as if there is an unregistered event that sets it back to read mode.

If i watch the event viewer the last event I get is OnEditContactClicked

but the contact card then leaves edit mode without any further actions being taken (i.e. don't click save or cancel)

Af: Jason Tiler Broad 22. jun 2017

RE: Open contact card in edit mode with WIN script

From a Windows Client VB Script use the following commands:

Set SoApp = CreateObject("SuperOffice.Application")

Call SoApp.SetSoProtocol("superoffice:contact.saleactivityarchive.udef.miniselectionmembers?&contact_id=665544&sale_id=123456")

SoApp.Context.SetEditMode (True)

Set SoApp = Nothing

 

SetSoProtocol sets to the protocol you want (selecting contact, and all other panels as you wish)

SoApp.Context.SetEditMode (True) switches the current main panel into EditMode

Af: Jochen Siegenthaler 22. jun 2017

RE: Open contact card in edit mode with WIN script

Hei Jason,
I am aware of this... It was for your information :-)

I am afraid I cannot plug this hole for you in 7.5.
Not a trivial part of my time is spend pluging holes. It is a never ending story!

Jochen's example running from an external process is not relevant because SetSoProtocol and the Context instance work synchronously. When this is running, the OS will have chosen some strategic time to interupt us.

You cannot from within a Save event put the card back into edit modus because the Save-And-Put-Card-In-Read-Mode is not yet terminated.

For this reason(s), I have added a PostSoProtocol method to the API which is safe to call from within any in-process script events as it will be defered until the app is in Idle.

But, this is not in 7.5!

Even if you set the ValidationMessage upon the OnEditContactClicked message, and this forces the user to at least input a valid number once and tab out, it will not plug the hole you are seeing. After clearing the ValidationMessage, the user can screw up the field once more and hit Save directly.

All you have to work with in 7.5 is the BeforeSave event where you could perhaps reset the field and show a message box.

Conrad

Af: Conrad Weyns 22. jun 2017

RE: Open contact card in edit mode with WIN script

Thanks for the info Conrad.

As I feared I'm going to have to make a workaround where I save the starting values in both fields and replace as required.

Cancelchanges called OnBeforeSave doesn't work either :-) It does reset the builtin fields but not userdef fields that have been edited

.

Af: Jason Tiler Broad 26. jun 2017

RE: Open contact card in edit mode with WIN script

CancelChanges is an illegal call to make from inside a SaveModel.
It is guarded against. The fact that it did anything at all is most probably a hole in 7.5.

It would be great if we could code in such a way as to allow any call from anywhere at any time.. and make it all work 100%! The problem is, I don't think we'd ever be able to release anything then.
Don't forget your script is not necessarily alone at pulling a model in some direction.

Conrad

Af: Conrad Weyns 26. jun 2017