You are viewing this site as a guest. You can still ask questions and help others! Join our Dev2Dev IT Community to receive your own blog, share your knowledge, and much more.

Read data using AE and insert through CI

2 replies [Last post]
Anand's picture
User offline. Last seen 6 years 30 weeks ago. Offline
Joined: 05/14/2011
Posts: 3

Hi ,
Can any one help me on this issue
Read the data using Filelayout(csv) and inserted through the component interface.

Thanks in Advance,
Anand

Hari_aindian's picture
User offline. Last seen 7 years 2 weeks ago. Offline
Joined: 08/02/2010
Posts: 84
Re: Read data using AE and insert through CI

What is your issue? explain that?

Rajendra Prasad's picture
User offline. Last seen 6 years 17 weeks ago. Offline
Joined: 08/08/2011
Posts: 7
Re: Read data using AE and insert through CI

Hi,
please hav look the below code for CI to insert data into record......
before this u need to create File Layout to upload the data from csv file into a staging record or temporary record....then use the CI code to insert the data from staging records to your actual records...
hope this helpful for u..\
Let me know if u need further concerns.

Local File &fileLog;
Local ApiObject &oSession, &oTsEmpdtlsCi;
Local ApiObject &oTsEmpdtlsLvl1Collection, &oTsEmpdtlsLvl1;
Local ApiObject &oTsEmpdtlsLvl2Collection, &oTsEmpdtlsLvl2;
Local Rowset &RS;
Local Record &REC;

Function errorHandler()
Local ApiObject &oPSMessageCollection, &oPSMessage;
Local number &i, &KK, &COUNT;
Local string &sErrMsgSetNum, &sErrMsgNum, &sErrMsgText, &sErrType;

&oPSMessageCollection = &oSession.PSMessages;
For &i = 1 To &oPSMessageCollection.Count
&oPSMessage = &oPSMessageCollection.Item(&i);
&sErrMsgSetNum = &oPSMessage.MessageSetNumber;
&sErrMsgNum = &oPSMessage.MessageNumber;
&sErrMsgText = &oPSMessage.Text;
&fileLog.WriteLine(&sErrType | " (" | &sErrMsgSetNum | "," | &sErrMsgNum | ") - " | &sErrMsgText);
End-For;
rem ***** Delete the Messages from the collection *****;
&oPSMessageCollection.DeleteAll();
End-Function;

&fileLog = GetFile("C:\CI\TS_EMPDTLS_CI.log", "w", "a", %FilePath_Absolute);

&fileLog.WriteLine(" BEGIN PROCESSING");

&RS = CreateRowset(Record.TS_EMPDTLS_TMP);
&RS.Fill();

&COUNT = &RS.ActiveRowCount;
&fileLog.WriteLine("ROW COUNT :" | &COUNT);

try

For &KK = 1 To &RS.ActiveRowCount

&REC = &RS.GetRow(&KK).GetRecord(Record.TS_EMPDTLS_TMP);
&fileLog.WriteLine("EMPLID :" | &REC.TS_50884_EMPLID.Value);
rem ***** Set the Log File *****;

&fileLog.WriteLine("Begin");
rem ***** Get current PeopleSoft Session *****;
&oSession = %Session;

rem ***** Set the PeopleSoft Session Error Message Mode *****;
rem ***** 0 - None *****;
rem ***** 1 - PSMessage Collection only (default) *****;
rem ***** 2 - Message Box only *****;
rem ***** 3 - Both collection and message box *****;
&oSession.PSMessagesMode = 1;

rem ***** Get the Component Interface *****;
&oTsEmpdtlsCi = &oSession.GetCompIntfc(CompIntfc.TS_EMPDTLS_CI);
If &oTsEmpdtlsCi = Null Then
errorHandler();
REM throw CreateException(0, 0, "GetCompIntfc failed");
End-If;

rem ***** Set the Component Interface Mode *****;
&oTsEmpdtlsCi.InteractiveMode = False;
&oTsEmpdtlsCi.GetHistoryItems = True;
&oTsEmpdtlsCi.EditHistoryItems = False;

rem ***** Set Component Interface Get/Create Keys *****;
&oTsEmpdtlsCi.TS_50884_EMPLID = &REC.TS_50884_EMPLID.Value;

rem ***** Execute Get *****;
rem If Not &oTsEmpdtlsCi.Get() Then
rem ***** No rows exist for the specified keys.*****;
rem errorHandler();
rem throw CreateException(0, 0, "Get failed");
rem End-If;

rem ***** Execute Create ******;
If Not &oTsEmpdtlsCi.Create() Then
rem ***** Unable to Create Component Interface for the Add keys provided. *****;
&fileLog.WriteLine(" CREATE CI FAILED ");
errorHandler();
REM throw CreateException(0, 0, "Create failed");
Else
&fileLog.WriteLine(" CREATE CI SUCCESS ");
End-If;

rem ***** Begin: Get/Set Component Interface Properties *****;
rem ***** Get/Set Level 0 Field Properties *****;

&oTsEmpdtlsCi.TS_50884_ADDRSDTLS = &REC.TS_50884_ADDRSDTLS.Value;

&oTsEmpdtlsCi.TS_50884_EMPLID = &REC.TS_50884_EMPLID.Value;

&oTsEmpdtlsCi.TS_50884_EMPNAME = &REC.TS_50884_EMPNAME.Value;

&oTsEmpdtlsCi.TS_50884_MONTHSAL = &REC.TS_50884_MONTHSAL.Value;

&oTsEmpdtlsCi.TS_50884_PHONENO = &REC.TS_50884_PHONENO.Value;
<*
rem ***** Set/Get TS_EMPDTLS_LVL1 Collection Field Properties -- Parent: PS_ROOT Collection *****;
&oTsEmpdtlsLvl1Collection = &oTsEmpdtlsCi.TS_EMPDTLS_LVL1;
Local integer &i19;
For &i19 = 1 To &oTsEmpdtlsLvl1Collection.Count;
&oTsEmpdtlsLvl1 = &oTsEmpdtlsLvl1Collection.Item(&i19);
&fileLog.WriteLine("&oTsEmpdtlsLvl1.JOBCODE = " | &oTsEmpdtlsLvl1.JOBCODE);
rem &oTsEmpdtlsLvl1.JOBCODE = [*];
&fileLog.WriteLine("&oTsEmpdtlsLvl1.LOCALITY = " | &oTsEmpdtlsLvl1.LOCALITY);
rem &oTsEmpdtlsLvl1.LOCALITY = [*];

rem ***** Set TS_EMPDTLS_LVL2 Collection Field Properties -- Parent: TS_EMPDTLS_LVL1 Collection *****;
rem &oTsEmpdtlsLvl2Collection = &oTsEmpdtlsLvl1.TS_EMPDTLS_LVL2;
Local integer &i212;
For &i212 = 1 To &oTsEmpdtlsLvl2Collection.Count;
&oTsEmpdtlsLvl2 = &oTsEmpdtlsLvl2Collection.Item(&i212);
&fileLog.WriteLine("&oTsEmpdtlsLvl2.END_DT = " | &oTsEmpdtlsLvl2.END_DT);
rem &oTsEmpdtlsLvl2.END_DT = [*];
&fileLog.WriteLine("&oTsEmpdtlsLvl2.START_DT = " | &oTsEmpdtlsLvl2.START_DT);
rem &oTsEmpdtlsLvl2.START_DT = [*];
&fileLog.WriteLine("&oTsEmpdtlsLvl2.TS_50884_HOTEL = " | &oTsEmpdtlsLvl2.TS_50884_HOTEL);
rem &oTsEmpdtlsLvl2.TS_50884_HOTEL = [*];
End-For;
End-For;
rem ***** End: Get/Set Component Interface Properties *****;

*>

rem ***** Execute Save *****;
If Not &oTsEmpdtlsCi.Save() Then
errorHandler();
REM &fileLog.WriteLine("SAVE FAILED FOR " | &REC.TS_50884_ADDRSDTLS.Value);
REM throw CreateException(0, 0, "Save failed");
Else

REM &fileLog.WriteLine("SAVE SUCESS FOR " | &REC.TS_50884_ADDRSDTLS.Value);
End-If;

rem ***** Execute Cancel *****;
If Not &oTsEmpdtlsCi.Cancel() Then
errorHandler();
REM throw CreateException(0, 0, "Cancel failed");
REM &fileLog.WriteLine("CANCEL FAILED FOR " | &REC.TS_50884_ADDRSDTLS.Value);
Else
REM &fileLog.WriteLine("CANCEL FAILED FOR " | &REC.TS_50884_ADDRSDTLS.Value);
End-If;

End-For;

catch Exception &ex
rem Handle the exception;
&fileLog.WriteLine(&ex.ToString());
end-try;

&fileLog.WriteLine(" END PROCESSING");

&fileLog.WriteLine("End");
&fileLog.Close();

Raj