Wednesday 28 October 2015

Many times I have been asked by customers to copy the personalization settings of one user to another. It could just be relating to one form or to replicate the whole user settings from one to another. The code below would just do that job. If it is selective copy then either elementName or designName fields can be filtered. I have been using this code on regular basis and has been quite helpful and updating personalization.
static void copyUserPersonalisations(Args _args)
{
    str userFrom = "";//userId to copy from
    str userTo = ""; //userId to copy to
    SysLastValue sysLastValueTo, sysLastValueFrom;
    int iCount=0;
    ;

    //refreshes all the records for the destination user.
    delete_from sysLastValueTo where sysLastValueTo.userId == "XXX";

    while select sysLastValueFrom where sysLastValueFrom.userId == "XXX"
    {
        select forUpdate sysLastValueTo;
        ttsBegin;
        sysLastValueTo.company = sysLastValueFrom.company;
        sysLastValueTo.designName = sysLastValueFrom.designName;
        sysLastValueTo.elementName = sysLastValueFrom.elementName;
        sysLastValueTo.isKernel = sysLastValueFrom.isKernel;
        sysLastValueTo.recordType = sysLastValueFrom.recordType;
        sysLastValueTo.userId = userTo;
        sysLastValueTo.value = sysLastValueFrom.value;
        sysLastValueTo.insert();
        iCount++;
       
        ttsCommit;
    }
    info(strFmt("Records from %1 is copied to %2. \n\rTotal Records copied: %3",userFrom,userTo,iCount));

}