Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Importing and Updating Form

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

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Importing and Updating Form

    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.

  • fireblaster Profile Picture
    fireblaster 40 on at
    RE: Importing and Updating Form

    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?

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Importing and Updating Form

    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);
    	...
    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans