web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Importing and Updating Form

(0) ShareShare
ReportReport
Posted on by 40

Hi there, I want to write a code for importing csv file to my form and my code is working, but the problem is, I want to update the form and check whether the importing files existed or not, if its exist then the data is updated, if its not, then it will be inserted into the form. my form should be like this and the FormOne should not have the same ID appear more than once, so I would use my unique field which is the ID

0407.WhatsApp-Image-2021_2D00_07_2D00_27-at-10.48.11-AM-_2800_1_2900_.jpeg

and my code is like this 

private void importRunBaseBatch()
{
CommaTextIO textIO;
container c;
HeaderGrid HeaderGrid;
LineGrid LineGrid;
ImportRunBaseBatch importRunBaseBatch;
int i;
NoYes NoYes;
boolean first;
;

textIO = new CommaTextIo(path, "R");
textIO.inFieldDelimiter(",");
textIO.inRecordDelimiter("\r\n");

c = textIO.read();

while (textIO.status() == IO_Status::Ok)
{
if(first == false)
{
first = true;
c = textIO.read();
continue;
}

if(conLen(c) > 1)
{
HeaderGrid.clear();
HeaderGrid.FullName = conPeek(c,1);
HeaderGrid.ID = conPeek(c,2);
LineGrid.ID = conPeek(c,2);
LineGrid.Name1 = conPeek(c,3);
LineGrid.Name2 = conPeek(c,4);
HeaderGrid.insert();
LineGrid.insert();

a = HeaderGrid.ID;

}

i++;
c = textIO.read();
}
info(strFmt("%1 records imported.", i));

}

anyone has the idea how to solve this? very much thanks in advance

I have the same question (0)
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    A typical solution is implementing exist() method and checking if the record doesn't already exist:

    str id = conPeek(c,2);
    if (!HeaderGrid::exist(id))
    {
       ...
    }

    Another approach, requiring less requests to database, is storing the information about already processed IDs in a collection:

    Set importedIds = new Set(Types::String);
    str id = conPeek(c,2);
    
    if (!importedIds.in(id))
    {
    	importedIds.add(id);
    	...
    }

  • fireblaster Profile Picture
    40 on at

    I already tried both solution but seems it has a problem, the variable c after conPeek isn't declared, should I just put the method in the import class?

  • Verified answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    conPeek() can't "undeclare" a variable. The variable must be declared before using the variable, and you also need to populate the container before you can extract anything from it with conPeek().

    You had the declaration in your original code - it was the second variable declaration inside importRunBaseBatch(). It seems that you've deleted it by mistake.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans