NAS & Job Ledger Entry

charlpcharlp Member Posts: 21
edited 2006-07-06 in Navision Attain
Hi there,

I have a problem, which I can't seem to solve and was hoping someone out there can help.

I have written a codeunit to run reports 1213, 1214, 1294 and 1295 all consecutively. The reports are the four batch jobs "Calculate Job Recognition", "Calculate Job WIP Value", "Post Job Recognition to G/L" and "Post Job WIP Value to G/L".

The idea was to run all the reports with a one click procedure. I then decided to automate the task using NAS. I wrote a .NET app to start and stop the NAS service, and pass the required parameters.

My company primarily uses Database Authentication, but since NAS will only work with Windows Authentication, I set up the service to start using the domain administrator's credentials. NAS runs on the same server as the NAV database server. I set up a scheduled task using windows' scheduler, and set this too to run using the domain administrator's credentials.

The domain administrator was set up in Navision as a Windows Login, and was given the ALL and SUPERUSER roles.

When I open a client, logging into the Database Server as the domain administrator, and I run the above mentioned codeunit, it runs with no errors and all is well.

When the windows scheduler starts NAS though, using the domain administrator's credentials, I get a "You do not have permission to modify records in the Job Ledger Entry table." error in the system event log, and thats where it ends.

My codeunit is as follows:
AutoJobWIPValueAndRecognition()
JobSetup.GET;

//Check the number series
IF GUIALLOWED THEN BEGIN
   JobSetup.TESTFIELD(KBAutoJobWIPNos);
   JobSetup.TESTFIELD(KBAutoJobRecogNos);
   JobSetup.TESTFIELD(KBSaveResultsToFolder);
END ELSE
   IF (JobSetup.KBAutoJobWIPNos='') OR (JobSetup.KBAutoJobRecogNos='') OR (JobSetup.KBSaveResultsToFolder='') THEN
      EXIT;

//Generate two new numbers
NoSeriesMgt.InitSeries(JobSetup.KBAutoJobWIPNos,'',WORKDATE,WIPNo,Buffer);
NoSeriesMgt.InitSeries(JobSetup.KBAutoJobRecogNos,'',WORKDATE,RecogNo,Buffer);

//Clear the variables
CLEAR(JobRec);
CLEAR(JobLedEntryRec);
CLEAR(TempFolder);
CLEAR(ZipFolder);
CLEAR(WIPFile);
CLEAR(RecogFile);
CLEAR(CalculateJobWIPValue);
CLEAR(PostJobWIPValuetoGL);
CLEAR(CalculateJobRecognition);
CLEAR(PostJobRecognitiontoGL);
CLEAR(Subject);
CLEAR(Body);

//Get the system's temp folder
TempFolder := KBGenFuncCU.GetTempFolder;
WIPFile := TempFolder + '\' + WIPNo + '.html';
RecogFile := TempFolder + '\' + RecogNo + '.html';

JobRec.RESET;
JobLedEntryRec.RESET;

//Calculate WIP Value
CalculateJobWIPValue.SETTABLEVIEW(JobRec);
CalculateJobWIPValue.SETTABLEVIEW(JobLedEntryRec);
CalculateJobWIPValue.USEREQUESTFORM(FALSE);
CalculateJobWIPValue.RUN;

//Post WIP Value to G/L
PostJobWIPValuetoGL.InitializeRequest(0, '', WORKDATE, WIPNo);
PostJobWIPValuetoGL.SETTABLEVIEW(JobRec);
PostJobWIPValuetoGL.SETTABLEVIEW(JobLedEntryRec);
PostJobWIPValuetoGL.USEREQUESTFORM(FALSE);
PostJobWIPValuetoGL.SAVEASHTML(WIPFile);

//Calculate recognition
CalculateJobRecognition.SETTABLEVIEW(JobRec);
CalculateJobRecognition.SETTABLEVIEW(JobLedEntryRec);
CalculateJobRecognition.USEREQUESTFORM(FALSE);
CalculateJobRecognition.RUN;

//Post recognistion to G/L
PostJobRecognitiontoGL.InitializeRequest(0, '', WORKDATE, RecogNo);
PostJobRecognitiontoGL.SETTABLEVIEW(JobRec);
PostJobRecognitiontoGL.SETTABLEVIEW(JobLedEntryRec);
PostJobRecognitiontoGL.USEREQUESTFORM(FALSE);
PostJobRecognitiontoGL.SAVEASHTML(RecogFile);

//Save the result set to file
IF KBGenFuncCU.StrEndsWith(JobSetup.KBSaveResultsToFolder, '\', FALSE) THEN
   ZipFolder := JobSetup.KBSaveResultsToFolder
ELSE
   ZipFolder := JobSetup.KBSaveResultsToFolder + '\';

ZipFile := ZipFolder + COMPANYNAME + '_' + WIPNo + '_' + RecogNo + '.zip';
KBZipCU.ZipFileName_Set(ZipFile);
IF KBZipCU.AddFileToZipQueue(WIPFile) THEN;
IF KBZipCU.AddFileToZipQueue(RecogFile) THEN;
IF KBZipCU.ProcessZipQueue THEN;

//Send notification email
IF JobSetup.KBAutoJobWIPRecogNotify <> '' THEN BEGIN
   InitCrLf;
   Subject := 'Job WIP & Recognition - ' + COMPANYNAME + ' - ' + FORMAT(WORKDATE) + ' ' + FORMAT(TIME);
   Body += STRSUBSTNO(Text0001, COMPANYNAME) + CrLf + CrLf;
   Body += STRSUBSTNO(Text0002, WIPNo) + CrLf;
   Body += STRSUBSTNO(Text0003, RecogNo);
   IF KBMailCU.SendMessage(JobSetup.KBAutoJobWIPRecogNotify,'',Subject,Body,'') THEN;
END;

//Delete the temp files
IF EXISTS(WIPFile) THEN KBGenFuncCU.DeleteFile(WIPFile);
IF EXISTS(RecogFile) THEN KBGenFuncCU.DeleteFile(RecogFile);
InitCrLf()
CrLf[1] := 10;
CrLf[2] := 13;
Cr[1] := 10;

I know our current license doesn't allow as to write entries to the Job Ledger Entry table directly, but why would the procedure work when I run it via the Client but not via NAS?

Regards,

Charl Pohlmann

Answers

  • krikikriki Member, Moderator Posts: 9,112
    You have to put the Windows credentials of the NAS service as the domain administrator.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • ara3nara3n Member Posts: 9,256
    I don't think he is running nas as service. Because he mentioned that he is using windows scheduler? If he is running it from cprompt then i guess he needs to pass paramaters for login?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • krikikriki Member, Moderator Posts: 9,112
    ara3n wrote:
    I don't think he is running nas as service. Because he mentioned that he is using windows scheduler? If he is running it from cprompt then i guess he needs to pass paramaters for login?
    I think it is better to install the NAS as a service and use the domain admin login and manual start/stop.
    Create 2 batchfiles to start and stop the service (or only start in case you don't use singleinstance codeunits. at the end of all the Navision commands you can put a COMMIT and then an error to let the NAS crash (instead of just stopping it).
    In the scheduler you only need a "NET START NASSERVICE" to start the service.

    PS I hope your license is enable to use the NAS, otherwise you can never use the NAS.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • kinekine Member Posts: 12,562
    There is known bug on NAS in older (3.x0) versions of Navision, when the codeunit rights are not working correctly. Try to find some hotfix or ask Microsoft if hotfix for that is available...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • charlpcharlp Member Posts: 21
    Thanks for all the replies guys.

    The following instances all use the domain admin's credentials:
    1. The .NET app, which starts and stops the NAS service.
    2. NAS.
    3. The Windows Login setup in Navision.

    The .NET app uses the ServiceManager class to start and stop NAS.

    Our license does include NAS, because I'm already using it to run/automate other processes.

    It is just this one which won't play along.

    The essence of the problem is that I can run the codeunit from the client, logged in as the domain admin, but get a permissions error when NAS runs it, logged in as the domain admin.

    Thanks kine, I will try to get hold of the hotfixes.

    Regards,
    Charl
  • charlpcharlp Member Posts: 21
    I have managed to solve this issue, compliments of Craig Barberini of UCS Software in South Africa.

    All four the reports mentioned in my initial post updates the Job Ledger Entry table. Craig suggested that I add a function to my calling codeunit, which will accept an argument of type Job Ledger Entry as ByRef. The only thing this function then does, is to run the MODIFY function on the record. The permissions on the CodeUnit was then set as : TableData Job Ledger Entry=rimd

    All four reports were modified to call my codeunit's update function, instead of the record's MODIFY function, passing the record which needs to be modified as an argument.

    This worked like a charm, and I can now run the codeunit from NAS without any errors.

    Regards,
    Charl
Sign In or Register to comment.