BPM to Update or Create Method Directive for JCSyst

Is it possible to create or update the JCsyst table via a BPM? I need to update the NextJobNumber or have it pull the nextjobnumber from another table.

WARNING… This is not for the faint of heart… but doing it with Business objects is better than directly updating it.
Warning 2 You can create your OWN counters using these business objects
Warning 3 Changing standard numbers that are normally system controlled may cause unpredictable results… The normal system “next” numbers may not take kindly to being reset to values where they might stomp on previously created values.
Disclaimers done…
There are Business Objects specifically defined to modify these values. There are TWO possible places that “Next” numbers are saved… one is Database specific, and one is COMPANY specific… i believe that Jobs are company specific.

Company Specific next values
//Add Reference:
Erp.Internal.Lib.Shared.dll
//Add Using:
Using Erp.Internal.Lib;
Using Ice.Common;
The command to reset any value is:

string KeyForNextNumber = "NextJobNumber";
int NewNext = 1234;
nv.SetCurrentCompanySequence(MyCust.Company,KeyForNextNumber,NewNext);

FYI, you can also “get the next value” with the following command:

int NextValue = nv.GetNextCompanySequence(MyCust.Company, KeyForNextNumber);

DATABASE Next Values
There are some counters that are database specific rather than company specific… to update and use those,
These need :
Include: Ice.Lib
Reference: Ice.Lib.NextValue

//this gets increments the next number and returns it:
var nv = new NextValue(Db);
NextCustomerID =  nv.GetNextSequence(“NextCustomer_c”);


//this will CREATE the new Next key value (if necessary) and then resets the next value to 1313
var nv = new NextValue(Db);
int Junk = nv.GetNextSequence(“NextCustomer_c”);
NextValue.SetSequenceCurrentValue(“NextCustomer_c”, 1313);


//This will GET the current value of the next value without incrementing it:
var nv = new NextValue(Db);
Int CurrentValue =  nv.GetSequenceCurrentValue(Inputs.NextValueKey_chr.Value);
6 Likes

FYI, the GetSequenceCurrentValue method is no longer available in 10.1.600 and 10.2.100 as far as I know.

I can confirm these methods are still available in 10.1.600 and 10.2.100. Did you run into a problem trying to use them?

Are you saying GetSequenceCurrentValue is still there? I don’t see it in any of my environments.

Yes - make sure you add the reference (Ice.Lib.NextValue) and using statement (using Ice.Lib)

2 Likes

I know this is old, but I finally have some time to test it… and got some issues…
Tim you indicated:


//this will CREATE the new Next key value (if necessary) and then resets the next value to 1313
var nv = new NextValue(Db);
int Junk = nv.GetNextSequence(“NextCustomer_c”);

I am trying this in a DataDirective , I added the reference to Ice.Lib.NextValue
and in a code widget added the folowing:

(new Ice.Lib.NextValue(Db).GetNextSequence("NewRoute_c")) + 191000)

and this works as is the first time it ran it gave me 1 as my result. :+1:

But I already have some counter running already via a different way, and would like to “force” a starting counter value.

I tried the following:

var nv = new Ice.Lib.NextValue(Db);
int Junk = nv.GetNextSequence("NewRoute_c");
Ice.Lib.NextValue.SetSequenceCurrentValue(Db,"NewRoute_c", 1900025);//forcing a value
int Junk2 = nv.GetNextSequence("NewRoute_c");
this.PublishInfoMessage("Junk: " + Junk.ToString() + "Junk2: " + Junk2.ToString(), Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");

I am getting an endless saving … and end up getting error from the server:

EpicorServerException
Description: BPM runtime caught an unexpected exception of 'SqlException' type.

See more info in the Inner Exception section of Exception Details.
Inner Exception: The wait operation timed out
Program: System.Data.dll
Method: OnError
Original Exception Type: SqlException
SQL Line Number: 0
SQL Error Number: -2
Framework Method: InnerGetNextSequence
Framework Line Number: 75
Framework Column Number: 25
Framework Source: InnerGetNextSequence at offset 518 in file:line:column c:_Releases\ICE\RL3.2.300.0\Source\Server\Internal\Lib\NextValue\Sequence.cs:75:25

Server Trace Stack:    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Ice.Lib.Sequence1.InnerGetNextSequence(String sequence, Int32 blockSize) in c:\_Releases\ICE\RL3.2.300.0\Source\Server\Internal\Lib\NextValue\Sequence.cs:line 75 at Epicor.Customization.Bpm.DB6C172345138A47C6A76682B89B580D2C.InTranDirective_IncRoutePoly_287B0B5BDBD346E680FA2F6F736A1BC6.A001_CustomCodeAction() at Epicor.Customization.Bpm.DB6C172345138A47C6A76682B89B580D2C.InTranDirective_IncRoutePoly_287B0B5BDBD346E680FA2F6F736A1BC6.ExecuteCore() at Epicor.Customization.Bpm.DirectiveBase3.Execute(TParam parameters) in C:_Releases\ICE\ICE3.2.300.11\Source\Server\Internal\Lib\Epicor.Customization.BPM\DirectiveBase.Generic.cs:line 147

Inner Trace:
The wait operation timed out

Q1: What am I doing wrong?

Q2: This value is saved where ? (the “NewRoute_c” counter? ) in which table…

Thanks

Pierre

I was just looking all over for the NewCustomer_c value too; thought it should be in XaSyst or XbSyst, but it was not. Turns out, originally they put the codes in UDCodes, so I think that is a whole different ballgame. Maybe that is where your NewRoute_c value should be placed as well, I really do not know. I would have liked to have found it and converted a form customization to a method directive.

They’re likely going in there, hidden, rightfully so…

Is there a way to use this in a client side or Customization?