Hi,
I'm trying to achieve the following. I've defined a standard service code for a specific service order type. Whenever a user is now creating a service order with this order type I want the standard service code being applied on the moment the user is adding a service item line. Main reason for doing this is applying a standard set of items/resources for the service item line to avoid user is forgetting to enter service lines (or is not running the function for adding the standard service codes).
I've created a function which makes it possible from the service item record to automatically create the service order including the service item line and service lines linked to it (which are coming from the standard service code which is set on the selected service order type). I'm using the standard function InsertServiceLines from table 5998 and it's working fine. Below a snapshot of the code:
IF lRecStdServCode.GET(pServOrdertype."Standard Service Code") THEN BEGIN
lRecStdServItemGrCode.gFncComingFromServOrderType(lRecStdServCode);
lRecStdServItemGrCode.InsertServiceLines(pServItemLine);
END;
The problem I'm facing is that I want to do a similar thing when the user is creating the service header manually (so not selecting my function from the service item record) but just when the user is manually entering the service order, selecting the service order type and inserting the service item line. When I'm calling the function from the OnInsert trigger of the service item line, I'm not able to insert service lines linked to the service item line as they are not inserted yet. I've tried to add a COMMIT, but without a result. I've also tried to program it on the service order subform (changed the DelayedInsert to No) but all without the needed result.
Can somebody help me solving this? I prefer not to put it on the OnModify trigger as it is very likely the user is going into the service lines straight after inserting the service item line. If the service lines of the standard service code are not inserted by then the user might enter them manually (not all of them are forgetting them to put in) and when they modify the service item line later, we will end up with double service lines.
0
Comments
using the "Service Item No." OnValidate trigger in the service item line is the best idea, IMO. The service item lines have a "strange" primary key. You could enter the same service item several times... in this case, you only want one set of service lines per service item. So... a check would involve another field in the service item line (standard service lines created, boolean).
The code would look like this:
0. only execute when Service Item No. <>''
1. if your service order type requires the default lines, go on
2. filter the service lines by document type, document no. and service item no., and "standard service lines created = true"
3. if nothing is found, check if your service item line has a line no.
4. if you have no line no. , check if "standard service lines created = true"
5. if you find that no other line has the flag, or your own line without line no. doesn't have he flag, run your code.
This sounds a little redundant, but it also considers a possible DelayedInsert = true property.
with best regards
Jens
I think I will work around it by putting my code on the OnModify trigger or OnValidate of the repair status code field. The initial repair status code will block them from posting, so the repair status code needs to be updated to get the order posted. Only problem when the initial repair status code is set to posting allowed. Than I can have a scenario a user creates the order including service item line and hit post (not very likely though). In this case I won't have my standard service lines yet, unless I do the check before posting as well.
Dave
IF NOT lRecServItemLineTemp.GET(pServItemLine."Document Type",pServItemLine."Document No.",pServItemLine."Line No.") THEN BEGIN
UseTempRec := TRUE;
lRecServItemLineTemp.INIT;
lRecServItemLineTemp."Document Type" := pServItemLine."Document Type";
lRecServItemLineTemp."Document No." := pServItemLine."Document No.";
lRecServItemLineTemp."Line No." := pServItemLine."Line No.";
lRecServItemLineTemp."Service Item No." := pServItemLine."Service Item No.";
lRecServItemLineTemp.INSERT;
END;
IF lRecStdServCode.GET(lRecServOrderType."Standard Service Code") THEN BEGIN
lRecServItemLine.SETRANGE("Document Type",pServItemLine."Document Type");
lRecServItemLine.SETRANGE("Document No.",pServItemLine."Document No.");
lRecServItemLine.SETRANGE("Line No.",pServItemLine."Line No.");
lRecServItemLine.SETRANGE("Service Item No.",pServItemLine."Service Item No.");
lRecServItemLine.SETRANGE("Std. Service Codes applied",TRUE);
IF NOT lRecServItemLine.FINDFIRST THEN BEGIN
lRecStdServItemGrCode.gFncComingFromServOrderType(lRecStdServCode);
IF UseTempRec THEN BEGIN
lRecStdServItemGrCode.InsertServiceLines(lRecServItemLineTemp);
lRecServItemLineTemp.DELETE;
END ELSE lRecStdServItemGrCode.InsertServiceLines(pServItemLine);
EXIT(TRUE);
END ELSE
BEGIN
IF UseTempRec THEN
lRecServItemLineTemp.DELETE;
EXIT(FALSE);
END;
END ELSE
BEGIN
IF UseTempRec THEN
lRecServItemLineTemp.DELETE;
EXIT(FALSE);
END;
if your code insists on an existing service item line, my "standard" modification would be to either:
- put a currform.saverecord in the OnValidate-Trigger of the "Service Item No." field, or:
- remove the "DelayedInsert" property from the "Service Item Lines" subform, with additional code in OnInsertRecord(), to prevent an insert without service item no.
With respect to causality (service item line causes standard service lines) this would be my preferred solution.
with best regards
Jens