CRMscript freezes

I'm trying to update the company cards in Customer service with data from CRM
it could happen that the script takes long ... but if you do

for (se.execute(); !se.eof(); se.next())
{

Company c;
c.load(se.getField(0).toInteger());   //company ID
c.setValue("x_regiomanager", regioincrm);
c.save();

}

the script freezes while executing

The for next loop by itself runs fine if you only have a printline statement in it.. but as soon as you put the c.load everything goes wrong 

What happens here, anyone any suggestion how to overcome this?

Kind regards,
Jan-Willem

RE: CRMscript freezes

Hi,

It is difficult to say without more information, you did not mention anything about your criterias for SearchEngine. 

Von: Michel Krohn-Dale 29. Jan 2021

RE: CRMscript freezes

Hi, there are a couple of things you could check. First, make sure the ID you are trying to load is not 0. That'll cause issues.

Also, you can try using NSContactAgent and NSContact instead for the Company class. I've had some issues like this somewhere, but don't remember the specifics. Think it might have been in a scheduled script and that crash came when calling Customer.load(int), and the workaround I used was to use the NetServer (NS) classes instead.

Von: Frode Lillerud 29. Jan 2021

RE: CRMscript freezes

This might not be helpful at all, and I'm not sure if it would make your CRMScript stop either, but are you sure you haven't just misspelled your field name and/or variable?

c.setValue("x_regiomanager", regioincrm);

should potentially be

c.setValue("x_regionmanager", regioncrm);

?

Von: Espen Steen 3. Feb 2021

RE: CRMscript freezes

And, to add to Espens response, if the regionmanager is the same on all contacts, why not just update with SearchEngine?

SearchEngine se;
se.bypassNetServer(true);
se.addData("contact.x_field", value);
se.addCriteria("contact.field", "Operator", "Value");
se.update();

It would atleast go way faster than loading each company individually.

Von: Simen Mostuen Iversen 3. Feb 2021