0 votes

I need to define by a level of proximity my relations between CONT and USER or COMP and USER by using The USERROLE Field.

I try to do it into an OpenEditContextRelation2 but this context doesn't exist it return an error EntityView=''

Below a part of my dataSynchro where i try to edit relation between ntComp and ntUser.

      var Target = 11 // Cont
      var Detail = 1; // Cont_user
      var Key = K_CONTACT
      var DetailKey = 0

    DetailKey = 4  // User--> K_USER 4   

    var EditHandle = Database.OpenEditContextRelation2(Target, Detail, Key, DetailKey)

     try {
     var DataSet = Database.GetMasterDataSet(EditHandle, 0)



    Database.UpdateFields(EditHandle, 0, 'USERROLE', GetLookupKeyFromQuery(SQL,     DataStore.AsString('Proximité MAN'), 'K_CONT_USERROLE') );

    Database.CommitChanges(EditHandle, false)


I need of course to be able to change relation on the Edit context of each Entity. Comp and Cont.

asked in WorkFlow / Serverscript by (285 points)
Note that in terms of syntax formatting (indentations, spaces, position of curly braces, etc) there are multiple mistakes. Please focus on writing neat code.
Of course it's copy paste from the datashynchro tool to a webmail and copy past again form webmail. It's not the best way to have a neat code. :)

1 Answer

0 votes
Best answer

Hello Laurent.

In edit, you have to use the insertDetail/updateDetail operations instead of the context relations.

Here is a code snippet written with Efficy 11 that:
1. Inserts the current user into the contact (key=4)
2. Searches a userrole in the lookup by text, e.g "PM"
3. Updates the relation field CONT_USER.USERROLE with the lookup key value

I hope this example will help you.

function demo() {
    var k_Contact = 4
        k_User = Efficy.currentUserId();

    var editCont = Efficy.openEditContext(ntCont, k_Contact);
    setContactUserRole(editCont, k_User, "PM");

function setContactUserRole(editCont, k_User, r_userRole) {
    var userRole = Efficy.getLookupKeyFromValue2("LK_CONT_USERROLE", "USERROLE", r_userRole, true);
    Efficy.setUsers(editCont, k_User, false, false);
    Efficy.updateDetail2(editCont, ntUser, k_User, "USERROLE", userRole);
answered by (7.4k points)
selected by
1,246 questions
1,517 answers
328 users