Skip to Content
avatar image
Former Member

Not able to save in "Document Lifecycle Event" script

Hi

objective -> to manipulate some value and set to another filed and save.All this needs to be done while saving the doc.

In Rfx page , I have created two extention fields ( date type) , from which I am retrieving value and trying to set this value to another extended field in the same page. The script is able to set the value successfully but while trying to save the page , error message appearing " User has already modified the page .Can not be saved. Discard the page and reload again"

I am pesting the code

Please help me .

import java.io.*;

import java.text.*;

import java.util.*;

import com.frictionless.api.doccommon.masterdata.VendorIBeanHomeIfc ;

import com.frictionless.api.contracts.ContractIBeanHomeIfc;

import com.frictionless.api.doccommon.masterdata.purchasing.BusinessUnitIBeanHomeIfc;

import com.frictionless.api.doccommon.masterdata.PaymentTermIBeanHomeIfc;

import com.frictionless.api.rfx.RfxDocIBeanHomeIfc;

agreementBean = doc.getRootParentIBean();

rfxHome=IBeanHomeLocator.lookup(session,RfxDocIBeanHomeIfc.sHOME_NAME);

//To retrieve the start date

start_date = ""+doc.getExtensionField("effective_start_date").get(); // effective start date is extended field

dateFormat = new SimpleDateFormat("dd.MM.yyyy");

edate_temp = new Date(start_date);

effective_satrt_date = dateFormat.format(edate_temp); // formating the start date

// retrieving the year

start_date_temp= effective_satrt_date .substring((effective_satrt_date.indexOf('.')+1)) ;

start_date_month=Integer.parseInt(start_date_temp.substring(0,(start_date_temp.indexOf('.'))));

start_date_year= Integer.parseInt(start_date_temp .substring((start_date_temp.indexOf('.')+1))) ;

//To retrieve the end date

end_date= ""+doc.getExtensionField("effective_end_date").get(); //effective end date is extended field

edate_temp = new Date(end_date);

effective_end_date = dateFormat.format(edate_temp); // formating the end date

edate_temp = new Date(end_date);

effective_end_date = dateFormat.format(edate_temp); // formating the start date

// retrieving the year

end_date_temp= effective_end_date .substring((effective_end_date.indexOf('.')+1)) ;

effective_end_year=Integer.parseInt(end_date_temp.substring((end_date_temp.indexOf('.')+1)));

year_gap=effective_end_year- start_date_year;

if(year_gap ==1)

{

float calc=(year_gap/12.0F)*start_date_month;

if(doc.isObjectAccessModeView())

{

rfxHome.upgradeToEdit(doc);

doc.getExtensionField("year1").set(start_date_year" ""/"" "calc);

doc.getIBeanHomeIfc().save(doc);

rfxHome.downgradeToView(doc);

}

else{

doc.getExtensionField("year1").set(start_date_year" ""/"" "calc);

doc.getIBeanHomeIfc().save(doc);

}

}

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Mar 25, 2011 at 07:42 AM

    Hi Swastik,

    I think you forgot to first get the doc in Edit mode.

    Just before the save, get the Edit copy of the doc. Check the APIs

    regards,

    Vaibhav

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thank you very much for assisting me.

      Can you please clarify a bit your answer ? For saving the doc , I am using this script. Is it not correct ? If any error please let me know .

      if(doc.isObjectAccessModeView())

      {

      rfxHome.upgradeToEdit(doc);

      doc.getExtensionField("year1").set(start_date_year" ""/"" "calc);

      doc.getIBeanHomeIfc().save(doc);

      rfxHome.downgradeToView(doc);

      }

      else{

      doc.getExtensionField("year1").set(start_date_year" ""/"" "calc);

      doc.getIBeanHomeIfc().save(doc);

      }

  • avatar image
    Former Member
    Mar 28, 2011 at 07:42 AM

    Hi,

    I think following code needs to b corrected:

    rfxHome=IBeanHomeLocator.lookup(session,RfxDocIBeanHomeIfc.sHOME_NAME);

    you sud have

    rfxHome = doc.getParentIBean();

    This will get RFX IBeanHomeIFC

    Then on this write Upgrate to Edit

    Save

    then

    Downgrade to View

    also try removing the if - else part

    if(doc.isObjectAccessModeView())

    {

    }

    else{

    doc.getExtensionField("year1").set(start_date_year" ""/"" "calc);

    doc.getIBeanHomeIfc().save(doc);

    }

    Regards,

    Vaibhav

    Add comment
    10|10000 characters needed characters exceeded