Creating new user codes using Customization

Hii, so in the script editor in my customization tools, I’ve been trying to add a new user code using this C# code…
try{
userCodesAdapter = new UserCodesAdapter(this.oTrans);
userCodesAdapter.BOConnect();
userCodesAdapter.GetNewUDCodes(“ShipDestin”);
} catch (System.Exception ex) {
MessageBox.Show(ex.ToString());
}
but I keep getting this error. Which is weird cause Epicor managed to generate the CodeID (which in the image is “437”) which means that Epicor has been able to find the CodeTypeID, as for the company ID, it surely exists…

If anyone knows what’s going on or has code in which they have successfully added a new User Code, please help me out :'))

Thank you for all the help!

1 Like

Without seeing the full script, I can’t be sure but I think I might see the issue. GetNew methods usually create the new record in the dataset, but don’t actually update the database. You probably need to do something like this:

try{
    userCodesAdapter = new UserCodesAdapter(this.oTrans);
    userCodesAdapter.BOConnect();

    var UserCodeTableset = userCodesAdapter.GetNewUDCodes(“ShipDestin”);

    userCodesAdapter.Update( ref UserCodeTableset );

} catch (System.Exception ex) {
    MessageBox.Show(ex.ToString());
}

p.s. I’ll clean this up if it’s a mess, tried to type it on my phone.

3 Likes