Stuck while coding

nvermanverma Member Posts: 396
My manager just sent me a mail and he wants me to implement something for him right away. But I am sorta lost. I am not sure how to begin.

Instructions:
*****Modify the No. Series table to include a new boolean field called "Used for Fixed Assets". Also, modify the Purchase Header table to include the same boolean field "Used for Fixed Assets". *****When a user selects a No. Series that has "Used for Fixed Assets" checked, then transfer the checkmark to the Purchase Header as well. If a checkmark appears in this field on the purchase header, then the purchase documents (quotes, invoices, orders) that use the No. Series that has the checkmark will be limited to selecting Fixed Asset as the line type in the line section of the document

The part in '*****' was straight forward and I completed it. I am having trouble with the part after this:

Wrote it initally in OnOpenForm(), which I later realized didnt make sense because user has to select the No. series first and once his selection is done, then i have to look if the Used for fixed asset for that no. series is checked or not. So I ended up moving it to: OnAfterGetRecord on the form (no. series), which doesnt seem to do anything (the "Used for fixed assets" does not get checked even if the no. series is checked for that field.
IF "Used for Fixed Assets" = TRUE THEN
BEGIN
   PurchaseHeader."Used for Fixed Assets" = TRUE;

I am pretty sure I am missing something very stupid...
«1

Comments

  • KYDutchieKYDutchie Member Posts: 345
    Hi,

    I would not do it in the form but on the table, more specifically in the OnInsert trigger of the purchase header table.
    After the call to "InitRecord" I would read the NoSeries table (308) and set your boolean there.
    so it will look like this:
    IF NoSeries.GET("No.Series") THEN
      "Used for Fixed Assets" := NoSeries."Used for Fixed Assets";
    

    That should do the trick,

    regards,

    Willy
    Fostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.
  • SavatageSavatage Member Posts: 7,142
    Also note for future:
    IF "Used for Fixed Assets" = TRUE THEN
    for boolean you don't have to use the = true in your condition.

    IF "Used for Fixed Assets" THEN
    IF NOT "Used for Fixed Assets" THEN
    PurchaseHeader."Used for Fixed Assets" = TRUE;
    it's := not just =

    keep reading those books [-o<
  • nvermanverma Member Posts: 396
    HMMMM.....I just tried what you suggested and it worked :D . I guess now it makes alot more sense now. I was trying to do this simple thing for about 2-3 hours, but it didnt come to me. :( ](*,)

    Thanks savatage for the tip...i never knew that...
  • SavatageSavatage Member Posts: 7,142
    nverma wrote:
    I was trying to do this simple thing for about 2-3 hours..
    After 1 you should have been asking help from your senior, and explain you need more of their time and more training.
    Does your customer get charged for this time?
    If it wasn't for this forum would you have spent all day on this?
  • nvermanverma Member Posts: 396
    I am not really sure about the inside deals of the contract between the client and our company. or how the billing works. I just do my best and tell him how many hours I spent on it.

    My manager is on vacation thats why I couldn't ask him for his assistance. I am glad that you guyz are here to lend a hand. \:D/
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Savatage wrote:
    Does your customer get charged for this time?
    If it wasn't for this forum would you have spent all day on this?

    I don't want to imply anything about this particular case, but I definitely know of cases where a client was billed for the time that the developer spent on Mibuso. The company saw this as a reasonable thing to charge out as "research".

    These days developers need to be billable with in a very short time, so proper training is not really possible.
    David Singleton
  • SavatageSavatage Member Posts: 7,142
    I definitely know of cases where a client was billed for the time that the developer spent on Mibuso. The company saw this as a reasonable thing to charge out as "research".
    Then they should be nice enough to donate :mrgreen:
    http://www.mibuso.com/donation.asp
  • DenSterDenSter Member Posts: 8,304
    I definitely know of cases where a client was billed for the time that the developer spent on Mibuso. The company saw this as a reasonable thing to charge out as "research".
    Actually, I know of a case where the customer was charged for the time the developer waited for an answer, and the person that answered the question on mibuso was billed at double rate for the same time as an 'outside expert consultant'. So the developer might have waited around for 3 hours, answering the question may have taken a total of 10 minutes, but was charged to their customer as an outside consultant, also for 3 hours, and for twice the rate.
  • nvermanverma Member Posts: 396
    Sorry to bother you guyz once again, but I have a quick question:
    Once this condition is satisfied, the system should automatically set the Type (option field in purchase line) to be set to "Fixed Assets". To do this, I wrote this onInsert trigger in Purchase header.
    IF NoSeries.GET("No.Series") THEN
    BEGIN
      "Used for Fixed Assets" := NoSeries."Used for Fixed Assets";
    
    //*****************
    PurchLine.Type := PurchLine.Type::"Fixed Asset";
    PurchLine.Modify;
    //*****************
    END;
    

    To me this sorta makes sense, but apparently it doesnt make sense to the system since it doesnt do anything. :-k

    Why not??
  • dansdans Member Posts: 148
    You could try putting it on the OnNewRecord trigger on the line form.
    Microsoft Certified IT Professional for Microsoft Dynamics NAV

    Just a happy frood who knows where his towel is
  • nvermanverma Member Posts: 396
    I tried what you suggested. I had to create NoSeries record again and PurchHeader record again and I put in the same code in OnNewRecord (in purchase line subform). But nothing happened.
  • dansdans Member Posts: 148
    Could you show us the code ?
    Microsoft Certified IT Professional for Microsoft Dynamics NAV

    Just a happy frood who knows where his towel is
  • ChinmoyChinmoy Member Posts: 359
    Try the following code in the OnNewRecord trigger of the Purch Order Subform (Form no. 54):

    Declare a local variable: PurchHeader - Record - Purchase Header

    IF "Document No." <> '' THEN
    BEGIN
    IF NoSeries.GET("No.Series") THEN
    BEGIN
    PurchHeader.GET("Document Type","Document No.");
    IF PurchHeader."Used for Fixed Assets" THEN
    Type := Type::"Fixed Asset";
    END;
    END;
  • KYDutchieKYDutchie Member Posts: 345
    Nverma,

    please see your manager and ask for some more training. I will try and help you and even try and give you the solution.
    I will add notes to each step to clarify to you why I did the step.

    The way to solve this issue is:
    1. Create a new trigger on the Purchase Line table called for example CheckFixedAsset, this trigger should return a boolean value.
    The code for this trigger should be:
    GetPurchHeader;
       Exit(PurchHeader."Used for Fixed Assets" );
    
    I created a new trigger on the table just for the purpose of central code and ease of maintenance. Forms will eventually go away, but tables will remain. If your customer wants this changed later on, you only have to change it in one place and it will work the same everywhere it is used.

    2. On the all your purchase subforms (Order, Quote, Invoice, Credit Memo, Return Order) modify the existing code in the OnNewRecord trigger:
       Type := xRec.Type;
       CLEAR(ShortcutDimCode);
    
    into
       IF CheckFixedAsset THEN
         Type := Type::"Fixed Asset"
       ELSE
         Type := xRec.Type;
       CLEAR(ShortcutDimCode);
    
    I do not like to put code on Forms, but here I have to.

    3. On the Onvalidate Trigger of the Type field on the Purchase Line table add the following code:
      IF CheckFixedAsset THEN BEGIN
        IF ((Type <> type::" ") AND (Type <> Type::"Fixed Asset")) THEN BEGIN
         Error('Only the Line types of Fixed Asset and Comment (blank) are allowed!');
        END;
      END;
    
    I also allowed the " " blank option to be manually entered so your customer will be able to add "Comment Lines" or blank lines.

    I think this should do what is required, but please ask your manager for additional training. This will benefit you, your manager and your customers.
    It does you no good when we just give you the code to problems you run in, you will not learn from this.

    Let me know if you need more clarification on this.

    Regards,

    Willy
    Fostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.
  • nvermanverma Member Posts: 396
    I was trying to test out the code, but when I click on the Purchase Order form and run it, it gives me the follow error:

    You cannot makes any changes in the database until a transaction has been started.

    I tried applying this fix from Microsoft, but it doesnt seem to do anything. http://support.microsoft.com/kb/2250231
  • SavatageSavatage Member Posts: 7,142
    did you turn on the debugger and see which code is causing the issue?
  • nvermanverma Member Posts: 396
    Never mind, I was able to fix that error message. :D
  • SavatageSavatage Member Posts: 7,142
    You should share your solution, in case someone in the future runs into the same issue.
    Else it looks like you're just taking info when you need it and not helping others when they need it.
  • nvermanverma Member Posts: 396
    After debugging the code I came to realize that I was trying to modify the record before an insert. That's why the system threw the error message.

    I have a quick question for willy I tried to implement what you suggested: it gave me an error at this part
    IF CheckFixedAsset THEN
    Type := Type::"Fixed Asset"
    ELSE
    Type := xRec.Type;
    CLEAR(ShortcutDimCode);

    It kept saying that CheckFixedAsset must be either true or false...then I tried changing the statement to CheckFixedAsset = TRUE (savatage pointed out earlier that writing true would be just redundant...so why did the system throw and error saying the true/false is missing ](*,) )...then it gave me another error saying that you cannot assign a VOID to a boolean...

    Chinmoy/Willy - The biggest problem that I had with this particular task was I didn't know where to put the code initially. I mean how did you know that the code will go in OnNewRecord of the form??? What was your through process to determine that, this is the trigger the code will go in...

    Willy - Even initially, when you helped me determine how to assign the boolean to true based on the no. series that was selected. How did you know that the code will go in OnValidate trigger. Because when I was initially trying to implement this, I kept trying to find a place to put the code in the No. series table itself. I spent hours trying to debug the no. series table to figure out the exact point where the information would get transfered to purchase line table, I never realzied i was looking at the wrong place to put the code...What was your through process to determine that, this is the trigger the code will go in...

    sorry about the huge post...i am just trying to absorb all the knowledge and learn from my mistakes so when i face the same problem again...i would know how to solve it... :D
  • SavatageSavatage Member Posts: 7,142
    Trigger References:
    http://msdn.microsoft.com/en-us/library/dd301068

    This is where the training comes in. Instead of figuring stuff out as it comes up, with proper training you would have created different types of tests & situations. Trying & using each trigger to see what & when it gets activated and what they do.

    Perhaps with your free time you can try some excersizes. Knowing where to put your code is super important! As you can probably tell a huge time saver when you're not trying every trigger you an find to see if your code works there.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    KYDutchie wrote:
    I think this should do what is required, but please ask your manager for additional training. This will benefit you, your manager and your customers.
    It does you no good when we just give you the code to problems you run in, you will not learn from this.

    I disagree with this statement.

    In this particular case, the customer gets what he asked for, not what they really need, but a billable solution at least, and the consultant learns a valuable lesson in life "there is such a thing as a free lunch" and is able to mark down 2 days of billable time the "manager" (and I cringe when I think to use that word to describe nverma's boss) gets the work done without having to pay for training nor does he need to pay high salaries to trained consultants and developers, and is able to bill the customer the full price (unless you think that they will deliver this to the client for free).

    How many times have people been told "don't put code on forms" and yet they keep doing it, so it is nonsense to say people are learning any more. The only objective at the end of the day is billable hours.
    ](*,)
    David Singleton
  • David_SingletonDavid_Singleton Member Posts: 5,479
    By the way, I don't want my comments to be taken as anything derogatory against nverma, I am sure that he/she is doing everything possible to learn Navision and deliver high quality services to the client. My issue is with the management of companies that fail to see the long term benefits of training their Navision consultants and taking on a few high end people to get things moving.

    In the short term all those billable hours look great, but just wait a year or two down the line when they turn into free work.
    David Singleton
  • nvermanverma Member Posts: 396
    What is included in proper training??? I mean the only way to get better at something is if you keep at it and try new things and the only way to get good at NAV is if you read books(manuals), but that can only get you far to a certain degree. Isn't it more about practical experience?? The more you practice the better you get???

    The user of NAV (clients employees) are sorta slow I guess, they barely know how to use a computer, so we try to do everything in our power to customize the system so that they only have to do the essential.

    Its like you tell them, press f3 and you create a new card....go to no. field and press tab...it will generate a number...those are the instructions that are give to the employees...and they are all happy with that....since most of them are not very savy.... for someone like us, its not a big deal to select type as fixed asset....but for some of the users....its not such a common thing...they ended up selecting G/L as the type...so now we have G/L entries without a fixed asset card associated with it....so that's why i was told to make it a default, so there is no room for error.

    The way I have learned how to use NAV is by reading the manuals and writing the certification exams. In the manuals they don't really go through all the triggers...they only go cover the most important triggers.

    I think it would be so awesome if someone could make an in-depth manual about it and explain everything with examples. I have seen some books that tried to do this, but nothing really that would blow this fish called NAV out of the water.
  • nvermanverma Member Posts: 396
    Savatage- I know about triggers and stuff, but how did you know that to do a default value to be generated you need to put code in OnNewRecord trigger (OnNextRecord Trigger-- The system determines how to select the next record, for example after a user presses PAGE DOWN (in a card form)) and being honest that doesn't really mean much to me yet....I guess this is where experience seperate the freelancers and newbies (like moi)..... Its not like I sat down and i was like OnNewRecord should do the trick... :|

    I think one of you guyz should write a in depth detail book about this....or it is seems like a mamoth of a task...divide between you guyz...and then publish it....i am sure ppl that are just starting out would buy it....
  • SavatageSavatage Member Posts: 7,142
    edited 2012-07-05
    My issue is with the management of companies that fail to see the long term benefits of training their Navision consultants and taking on a few high end people to get things moving.
    You almost get the feeling like they come in and say, "well, here's your next project you know nothing about. Take your time someone else is paying anyway. Then once we fill there system with unnecessary coding and the system slows to a crawl, well sell them the solution for speeding up the system. By removing what we did and deleting keys."

    as an end user also it's very troubling. Most companies spend most of their time & effort on running their own company and not always focusing on the software behind it. We sometimes trust & believe this "Partner" is actually helping us, never thinking they are actually hurting us. Like, when they give us everything we ask to change without mentioning all the future problems and upgrading costs. If they tell you right off the bat that thousands of dollars can be saved, now & in the future, by doing it the Nav-Way rather then altering the entire system..then that's a good "Partner" and worth keeping.

    Sorry to hijack your post nverma.

    PS. there are books, tell your manager that the company should foot the bill and have these programming books in house!:
    http://www.packtpub.com/books?tid=2&ava ... k_limit=30
  • SavatageSavatage Member Posts: 7,142
    nverma wrote:
    The user of NAV (clients employees) are sorta slow I guess, they barely know how to use a computer, so we try to do everything in our power to customize the system so that they only have to do the essential.
    :-# Just like you need training so do they. And once they start using it on a daily basis you would be surprised how quickly they will pick it up.
    nverma wrote:
    Isn't it more about practical experience?? The more you practice the better you get???
    The point is you appear not not have alot of help & guidence. You shouldn't be getting it from a forum, is basically what we are saying. Your company should provide you proper training in the areas you need help in so you can provide solutions to your customers in a timely manner. I like to call it a WIN-WIN!
    Inastead of a STRUGGLE -FRUSTRATION!
  • KYDutchieKYDutchie Member Posts: 345
    David,

    you bring up a couple of good points and they are sometimes frustrating to me too:

    People are not learning anymore: True and not true.
    It is true for a lot of people that resort to these forums to get the answer, because it is easier to Google it then to figure it out themselves or invest in the proper education. However, me personally I spend quite a bit of my personal time trying to learn more about NAV by reading books about NAV, C\AL, SQL, .NET and just by trying things out in my own "play" databases. I do not see that a lot anymore.

    Secondly : "The only objective at the end of the day is billable hours." Absolutely true.
    But what I want to make clear is this and this is totally my personal opinion:
    Yes, billable hours are essential for business, but for me, so are customer satisfaction and a decent billable ratio.
    With this particular modification, and we don't know if it was a fixed bid or hourly rate, the customer could get charged over $2000 if it was an hourly rate.
    I don't think the customer would be happy with that and the customer would probably get upset with NAV and not the partner.
    Another example of this is that we are currently in a situation with a couple of our customers who we inherited from a partner that went out of business. These customers are highly upset with NAV because of the high customization costs they were charged. And when I look at the customization, I can understand why these customers are upset. They were charged a lot of money and it was not working. These customers were almost to the point of dropping NAV and giving NAV a bad name. And when NAV gets really bad reviews, that eventually hurts our business. Because one bad review is more powerful than 20 positive reviews.
    Next we should also consider the billable ratio of this programmer. Let's assume this was a 4 hour fixed bid modification. He now has spend 16 hours on a 4 hour modification budget, that is a ratio of only 25%. Eventually him and his "manager" will be held responsible for that ratio.

    I get frustrated too when people come on these forums and have a one line sentence demanding the complete code for a major modification. And like a lot of people I notice too that people are not trying anything themselves anymore. But in this particular thread I think Nverma was spending to much time trying.
    But most of all I get frustrated that people allow their customers to build customization into NAV so it looks and feels similar to their "old ERP" system, instead of training the customer to use NAV as it should be used. And modifying NAV just to get a couple of billable hours in is the worst thing anybody could do.

    I am sorry it became such an off-topic post, but I had to vent,

    Regards,

    Willy
    Fostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.
  • SavatageSavatage Member Posts: 7,142
    KYDutchie wrote:
    . Because one bad review is more powerful than 20 positive reviews.
    ...
    But most of all I get frustrated that people allow their customers to build customization into NAV so it looks and feels similar to their "old ERP" system, instead of training the customer to use NAV as it should be used. And modifying NAV just to get a couple of billable hours in is the worst thing anybody could do.
    Amen [-o<
  • David_SingletonDavid_Singleton Member Posts: 5,479
    In the Navision world, the road to disaster normally starts with the client saying...
    customer wrote:
    Yeah but in our old system....
    David Singleton
  • David_SingletonDavid_Singleton Member Posts: 5,479
    In the Navision world, the road to disaster normally starts with the client saying...
    customer wrote:
    Yeah but in our old system....

    Oh and sadly this is followed by the following discussion

    Consultant: "So if you wanted it to be like your old system, why did you buy Navision?"
    Client: "because your sales person told us that Navision could be customized to do everything that our old systme did and they showed us how easy it is to change the code to emulate what we do now."
    Consultant: ](*,) #-o :oops: :-#
    David Singleton
Sign In or Register to comment.