Page 1 of 1

Double relation in Servoy Mobile (create)

PostPosted: Tue Mar 05, 2013 11:02 am
by vincentc
Hello,

We are currently developping a Mobile application for Sage CRM thanks to Servoy Mobile. I have a question about how to retrieve a field value thanks to a double relation on a Mobile form (in the ws_create).

I give you an example.

In Sage CRM, this is the way to retrieve the telephone number of a Contact (table Person):

Person
pers_personid
(…)

Phone_Link
plink_phonelinkid
#plink_recordid (here equivalent to pers_personid)
#plink_entityid (always equivalent to the value '13' pour the entity Person)
(…)


Phone
phon_phoneid
#phon_phonelinkid
phon_number (the field that we want retrieve)
(…)


So we made 2 relations to retrieve the telephone number of a Contact:

svy_rel1.png
svy_rel1.png (5.28 KiB) Viewed 1849 times


and

svy_rel2.png
svy_rel2.png (5.38 KiB) Viewed 1849 times



svy_mob_form.png
svy_mob_form.png (8.43 KiB) Viewed 1849 times


With the "data" object in parameter, we are able to read the info (ws_read), as well as update (ws_update) but we are unable to retrieve the value of the phone number in the ws_create. Do you have an idea of ​​how to get it?

Thank you very much in advance.

Vincent

Re: Double relation in Seroy Mobile (create)

PostPosted: Tue Mar 05, 2013 11:34 am
by jcompagner
so you are saying in mobile you do create a new record, you do create a new relation (2 times) and you do fill in the phone number but that relation record you don't get in the sync to the server?
Do you have a ws_create on the table of that relation?

Re: Double relation in Seroy Mobile (create)

PostPosted: Tue Mar 05, 2013 1:00 pm
by vincentc
I answer "yes" to your two questions.

I have a ws_create on my phonelink table and on my phone table but these methods aren't fired (I think this is because the mobile form is based on the table Person).

Re: Double relation in Seroy Mobile (create)

PostPosted: Tue Mar 05, 2013 2:34 pm
by jcompagner
if new record are created through the relation then those new records should be pushed
please make an example where you have a mobile solution and a service solution and make a case from that.

Re: Double relation in Servoy Mobile (create)

PostPosted: Wed Mar 06, 2013 5:39 pm
by vincentc
Do you mean that I have to export my 2 solutions Mobile and Service (+ the war file) and send it to the support with the previous explainations ?
I currently use a SQL Server database (Sage CRM), isn't that a problem for the Servoy Support ?

Because of absence of reaction of the ws_create method of Phone and PhoneLink, I do the creation of these records manually in the ws_create of the Person table. But I can't retrieve the phone number newly created (data.person_to_phonelink.phonelink_to_phone.phon_number doesn't work)

Here is the code of the ws_create in my data_person form, maybe it will help you to understand that I want to do :


Code: Select all
function ws_create(data,version,pk)
{

   application.output(data, LOGGINGLEVEL.ERROR)
   //example of the content of the data object : {pers_firstname:Doug,modification_date:1362581796497,pers_personid:15,pers_lastname:Lasse,pers_companyid:66992,created_on_device:true}
        //Don't understand why the pers_personid is 115 ???

   
   var fsUsers = databaseManager.getFoundSet('veolia_waters','users')
   var fsCompany = databaseManager.getFoundSet('veolia_waters', 'company')
   //We load the record of the company under which we created the contact
   fsCompany.loadRecords(data.pers_companyid)
   
   fsUsers.loadRecords(globals.userid)
   
   var recCurUser = fsUsers.getSelectedRecord()
   var recCurCompany = fsCompany.getSelectedRecord()
   
   var CurPersonId = createPerson(recCurUser,data)
        (...)
   
   createPhone(recCurCompany,CurPersonId,data)                     
   
   databaseManager.saveData();
   
   foundset.loadAllRecords();

   databaseManager.saveData()
   
}


function createPerson(pRecCurUser,pData)
{
   var oldPersonId = globals.createSageCrm('Person')
   var rec = foundset.getRecord(foundset.newRecord());
   var today = new Date();
   
   rec.pers_personid = oldPersonId;
   rec.pers_firstname = pData.pers_firstname;
   rec.pers_lastname = pData.pers_lastname;
   rec.pers_companyid = pData.pers_companyid
   rec.pers_createdby = globals.userid;
   rec.pers_createddate = today;
   rec.pers_timestamp = today;
   rec.pers_channelid = pRecCurUser.user_primarychannelid
   rec.pers_secterr = pRecCurUser.user_primaryterritory
   
   return oldPersonId
}

function createPhone(pRecCurCompany,pRecCurPersonId,pData)
{
   
   if (pData.person_to_phonelink.phonellink_to_phone.phon_number) //this condition DOESN'T WORK
   {
      var today = new Date();
      var fsPhone = databaseManager.getFoundSet('veolia_waters','phone')
      var oldPhoneId = globals.createSageCrm('Phone')
      var recPhone = fsPhone.getRecord(fsPhone.newRecord());
   
      recPhone.phon_phoneid = oldPhoneId;
      recPhone.phon_countrycode = null;
      recPhone.phon_areacode = null;
           recPhone.phon_number = pData.person_to_phonelink.phonelink_to_phone.phon_number //DOESN'T WORK
      recPhone.phon_createdby = globals.userid;
      recPhone.phon_createddate = today;
      recPhone.phon_updatedby = globals.userid;
      recPhone.phon_timestamp = today;
      recPhone.phon_updateddate = today;
   }

   createPhoneLink(pRecCurCompany,pRecCurPersonId,pData,oldPhoneId)


}

function createPhoneLink(pRecCurCompany,pRecCurPersonId,pData,pRecCurPhoneId)
{
   var rec;
   var oldPhoneLinkId;
   var today = new Date();
   var fsPhoneLink = databaseManager.getFoundSet('veolia_waters','phonelink')
   var recPhoneLink;

        //If a phone number is typed in the Mobile app, create phone number for the Contact
        //Else, retrieve the phone of the contact Company

   if (pData.person_to_phonelink.phonellink_to_phone.phon_number)
   {
      oldPhoneLinkId = globals.createSageCrm('PhoneLink') //10331
      recPhoneLink = fsPhoneLink.getRecord(fsPhoneLink.newRecord());
      
      fsPhoneLink.plink_linkid = oldPhoneLinkId
      fsPhoneLink.plink_recordid = pRecCurPersonId
      fsPhoneLink.plink_entityid = 13
      fsPhoneLink.plink_phoneid = pRecCurPhoneId
      fsPhoneLink.plink_type = 'Business'
      fsPhoneLink.plink_createdby = globals.userid
      fsPhoneLink.plink_createddate = today;
      fsPhoneLink.plink_updatedby = globals.userid;
      fsPhoneLink.plink_updateddate = today;
      
      
      
   }
   else
   {

      //Search the phone number of the contact Company    
      fsPhoneLink.find()
      fsPhoneLink.plink_recordid = pRecCurCompany.comp_companyid
      fsPhoneLink.plink_entityid = 5
      fsPhoneLink.search()
      
      if (fsPhoneLink.getSize() > 0)
      {   
         rec = fsPhoneLink.getRecord(1); //fsPhoneLink.getRecord(i);

         oldPhoneLinkId = globals.createSageCrm('PhoneLink')
         recPhoneLink = fsPhoneLink.getRecord(fsPhoneLink.newRecord());
         
         fsPhoneLink.plink_linkid = oldPhoneLinkId
         fsPhoneLink.plink_recordid = pRecCurPersonId
         fsPhoneLink.plink_entityid = 13
         fsPhoneLink.plink_phoneid = rec.plink_phoneid
         fsPhoneLink.plink_type = rec.plink_type
         fsPhoneLink.plink_createdby = globals.userid
         fsPhoneLink.plink_createddate = today;
         fsPhoneLink.plink_updatedby = globals.userid;
         fsPhoneLink.plink_updateddate = today;
      }
      
   }
         
}

Re: Double relation in Servoy Mobile (create)

PostPosted: Wed Mar 06, 2013 6:53 pm
by jcompagner
we just need an example of the 2 solution files, we don't need a war file, just the servoy solutions

you could export with sample data, so we can test it on any database

Re: Double relation in Servoy Mobile (create)

PostPosted: Thu Mar 07, 2013 11:52 am
by vincentc
Case created (SVY-4097)

Thanks again!