Background Task on Navision 5

karlkarl Member Posts: 22
All,

Can anybody help me how to automate some activities on NAV 5?
Ex. We want to do invoice posting (batch job) every day on 6.00 pm (automatically). Is it possible? I've searched in this forum before and found something about NAS but I'm really new on this stuff. So, can anyone guide (or inspiring) me about using NAS and how it can solve my problem?

Regards,
Karel

Answers

  • DakkonDakkon Member Posts: 192
    Nas stands for Navision Application Server. It's basically a dumb client session that does a single given task (typically). First you have to install a nas server on a specific box. The nas runs as a service and will print any ERROR() or MESSAGE() to your event log (as well as start and stop messages). Next you have to edit the NASHandler function in codeunit 1 (make sure you don't modify anything else in this codeunit or you could seriously cause problems). The NASHandler function gets passed one argument "NASID" wich is the text you configure in the "Start-Up Parameter" field of the application server manager application. I don't want to get too much into the application server manager software other than to tell you that there should be a pdf file explaining the installation, setup and functioning of the nas on your product cd. It will likely be located under a folder named Nas or some such. I'm sure others on this forum could help you with the exact file name.
    Back to the NASHandler function. When your application server service starts, the first thing it does is call the NASHandler function and passes the start-up parameter text to it. You can see how the existing code parses the NASID parameter and then calls other codeunits based on the results. You will need to edit that code to look for your own NASID that you are going to pass and then call a codeunit (in which you will put the logic you wish to execute).
    Any code that runs under a nas must not open any forms or dialog boxes. There is a function in C/AL named GUIALLOWED that you can call within code to determine if that code is being run under a nas process. The GUIALLOWED function will return a false result if called from a nas process. You will need to make sure any code you call makes proper use of GUIALLOWED to avoid any dialogs/forms, otherwise you will get an error in the task when it tries to open one of these.
    ex.
    IF GUIALLOWED THEN
      myDialog.OPEN('some message');
    
    If any of this seems a bit confusing, I can understand and will be happy to answer further questions. Also, if you just want to schedule batch jobs, I wrote my own nas scheduler to run specified codeunits/processing reports at specified times and I would be happy to share the objects with you (of course you would need those object numbers in your license or you would need to renumber them to something that is within your license).
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
  • karlkarl Member Posts: 22
    Hi Dakkon,

    Thanks very much for your explanation, it is very enlighten me!
    I think this is what I looking for to solve my problem. So, steps are:
    1. Install Navision Application Server
    2. Specify a startup parameter for NAS
    3. Modify Code Unit 1 on NAV 5
    4. Apply NAS Scheduler (which is an object <is it a code unit?> in NAV that will be executed by NAS when it is started at first time). Is it correct? (Sorry if I've got it wrong.)

    Question is: what is to edit in code unit 1? I've checked on it and it has procedure named NASHandler(NASID): Text(260). Also, I'm very glad if you really can share your object about NAS scheduler.


    Thanks,
    Karel
  • jlandeenjlandeen Member Posts: 524
    If you're working with NAV 5.0 there is now a new module called Job Queue. It is a great out of the box module for these types of automations and comes with a startup parameter and everything setup in Codeunit 1 to run things without modifications. All you have to do is setup a NAS with the startup parameter of JOBQUEUE and setup the jobs in the Job Queue Entry table (use the Job Queue Entries form). You should be able to find all of these objects in the 400 to 500 range of tables, codeunits and forms.

    You can setup jobs that are linked to either reports or codeunits and you can have them run once or run at regular intervals with the Recurrence settings.

    One very important thing about writing code that runs on NAS....make sure that there are no confirm, message, dialog or other user interface elements that are invoked in your code. This is because a NAS instance does not have a user interface and will throw an error if encounters code that requires a UI.

    I've implemented this a few times now and it really works quite well.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • DakkonDakkon Member Posts: 192
    Yes you have it right. the scheduler would be a codeunit (which then may use a lot of other objects as needed). You would have to write all the code to do the actual scheduling in this fashion. There is more to setup than the start-up parameter with the nas service, but the pdf on your install cd will explain most of that. Here is the example code change I made to codeunit 1 for my scheduler:
       // SCHED1.00 - BEGIN
       IF (COPYSTR(Parameter,1,9) = 'SCHEDULER') THEN
       BEGIN
          SchedulerID := 'NAS1';
          IF STRPOS(Parameter,' ID=') > 0 THEN
             EVALUATE(SchedulerID,COPYSTR(Parameter,STRPOS(Parameter,'=') + 1));
          SchedulerManagement.SetID(SchedulerID);
          SchedulerManagement.RUN;
          SchedulerManagement.StartCountDown;
          CGNASStartedinLoop := TRUE;
       END;
       // SCHED1.00 - END
    
    The start-up parameter for my nas scheduler looks like either "SCHEDULER" or "SCHEDULER ID=MySchedulerID"
    I will be happy to share my objects. You will need to make some custom changes for them to fit into your system, since they rely on other custom pieces I wrote for our own system, but it wouldn't be difficult compared to writing a scheduler from scratch ;)
    My scheduler design allows you to run as many Nas's as you like as schedulers, each with their own ID so that you can designate certain tasks to run on a specific nas scheduler, or you could simply run multiple schedulers if you wished to ensure that one was always available to run a task. Keep in mind, your license must include each nas server you wish to run.
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
  • DakkonDakkon Member Posts: 192
    You make a very good point Jhandeen. I tend to forget that piece exists in 5.0. I do believe you will still need a granule for that if you are not running a solution center license, but I believe it's not too expensive (the exact number escapes me). If you just need to schedule a basic job that might work better for you than integrating my scheduler :)
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
  • jlandeenjlandeen Member Posts: 524
    Yes I don't think it's very expensive and it's all tested and integrated with NAV out of the box now. The one thing I don't think it does very well is to support any controlled load balancing of jobs across multiple NAS instances. It sounds like you've had to deal with that in the past...and I think that's a shortcoming of the Job Queue engine...but I think that could be added to the base NAV objects fairly easily.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • DenSterDenSter Member Posts: 8,304
    I agree with Jeff that they should go with the Job Queue. The job queue provides functionality to schedule tasks at certain times, without having to develop anything. It might be a granule cost (which I doubt will be a lot, since it's just a few objects and a NAS user), but it will be much better from a support point of view, and from an upgrade point of view.
  • jlandeenjlandeen Member Posts: 524
    Thanks Daniel....that's one other point of I glossed over. Out of the box functionality really helps from a maintenance and upgradability perspective. It also normally indicates that a module has been tested by many resources/client sites as opposed to only a few developers/analysts/users at 1 client which is the case with most custom modifications ;)
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • DenSterDenSter Member Posts: 8,304
    My main point was from a support point of view. With a one-time custom job, how ever easy it is to do, the only person that can realistically support it is the developer who did the mod. With Job Queue, every single support person (at partners as well as at Microsoft) *should* know how it works, or have easy access to someone who does.

    Say a few months from now you have an issue with the custom scheduler. You call your partner, they have their developer look at it, and before you know it, you spend 4-8 hours in consulting fees. Where I used to work that was $185 an hour, so you can see how fast that adds up. You purchase a granule, which might be a bit more right off the bat, but support (assuming that you are already paying for it) is already included at no additional charge.
  • DakkonDakkon Member Posts: 192
    I certainly agree. Also if you don't have the objects needed for the custom solution in your license already, you have to pay for those as well, which could end up being more than a granule depending on the number of objects and granule price. If you don't need load balancing or the ability to run specific tasks on their own dedicated scheduler, then my solution is probably overkill for your needs anyway :)
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
  • karlkarl Member Posts: 22
    Thanks all, for these enlighten suggestion.
    At least, now I've get more hint about NAS and multiple choice to pick (which I don't have any before) about how to implement this on my case.

    Regards,
    Karel
  • DenSterDenSter Member Posts: 8,304
    Do yourself a favor, and get in touch with your partner to get more information about the Job Scheduler, before you start spending money on designing and developing a custom solution. It might be exactly what you need for a price that is reasonable to you.
Sign In or Register to comment.