Adding Attachments to PO Lines during PO Generation/Creation within New PO Suggestions

According to my trace your ttPOSug should be empty in post Proc… Did you click “BUY” on these suggestions? My spidy-sense says this shouldn’t be working

Yes, they were marked as “BUY” and then I clicked generate.

Well… sh*t I’m dumbfounded… oh well if it ain’t broke… however I believe this will fail if they click “BUY” and then leave the screen or clear it and come back and hit generate later. I believe generate doesn’t actually care about what you have selected on the screen it generates ANY PoSug with the Buy Checkbox whether it is in the screen or not…
Not sure if that matters in your case but try it, open po Sug, Mark Buy… clear screen , load another POSug, (don’t mark buy) hit generate. I believe the original PO sug will still generate and its information will NOT be in the ttSug table.

1 Like

Boo, you’re right. It did not work.
I’ll have to mess around with this some more tomorrow…

You may have to try that Pre DD Post hack that should work regardless of which SugCreated since you’ll be triggering on Data Directive POHeader.Added… what a pain

Why not do this with a standard data directive on the Po Detail record… When a new PO Detail is added, then add the attachments. This way, it doesnt matter who or what method did the adding… it would even work when adding a line from the PO Screen.

1 Like

Good way to get a Dull pointer error.

2 Likes

+7 Points
image

3 Likes

@timshuwy Because I like to do things the hard way, apparently? :joy:

That’s alright; it’s just an object. I’ll just instantiate a new one.

1 Like

haha++;

But presumably if you were # with pointers, you’d be using c++ anyway :stuck_out_tongue:

1 Like

Okay, so I moved it over to an in-trans/standard directive and it works for both manual creation and PO generation. The one hitch I’m having troubles with now is when a user manually changes the part, I need it to delete all of the old ones before adding the new ones.
I had it working when everything was in the method directives, but now that it’s a data directive, the deletion and reattaching lags.
For instance, consider these two parts:
ABC which has 1 attachment.
DEF which has 8 attachments.

The original line was create for ABC and it brought in the 1 attachment. Great.
I switch it to DEF, save, and refresh, but the 1 attachment is still there. Hmm.
I switch it back to ABC, save, and refresh, and now ABC has the 8 attachments from DEF. More Hmms.

I’ve flipped it between standard, in-trans, a combination, a method directive, both pre and post, but I cannot seem to find the timing to get that to delete and then re-add for the current part.
image

If one is manually changing the PO, could you put a Button on the form that’d go get the attachments. Make it a slight change to the user process work flow?

I could, but I’d rather that be a last resort.
The more automated it is, the less user error there is.

1 Like

Hmmm can’t you ask them to delete the line and re-add it? I hate the idea of them changing the part number on the line after the PO is created…

1 Like

Alos did you try moving the delete to happen on the ChangePartNum method? instead of the data directive?>

That would be taking the easy way out. :stuck_out_tongue:

Yes, in fact that’s where it started out life. Same behavior, though.

I’d go back and investigate the ChangePartNum option… Delete the attachments in pre-processing in ChargePartNum?

I have tried it on both pre and post with no luck.

Is it my code?

      var ttPODetailR = ttPODetail.FirstOrDefault(r=>r.Updated());
      const string RELATEDTYPE = "PODetail";
      const string RELATEDSCHEMA = "Erp";
      int iter = 0;

      if( ttPODetailR != null )
      {
         string strPNum = ttPODetailR.PONUM.ToString();
         int pNum = (int)ttPODetailR.PONUM;
         string strPLine = ttPODetailR.POLine.ToString();
         int pLine = (int)ttPODetailR.POLine;

         var count = (
            from xa in Db.XFileAttch.With(LockHint.NoLock)
            where xa.Company==Session.CompanyID &&
                     xa.RelatedToFile==RELATEDTYPE &&
                     xa.RelatedToSchemaName==RELATEDSCHEMA &&
                     xa.Key1==strPNum
            select xa.AttachNum).Count();

         if( count > 0 )
         {
            using( var poBO = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.POSvcContract>(Db))
            {
               POTableset poTS = new POTableset();
               poTS = poBO.GetByID(pNum);
               while( iter < count )
               {
                  if( poTS.PODetailAttch[iter].POLine == pLine )
                  {
                     poTS.PODetailAttch[iter].RowMod = "D";
                  }
                  iter++;
               }
               poBO.Update(ref poTS);
            }
         }
      }

Try
poTS.PODetailAttch[iter].SetRowState(IceRowState.Deleted);

instead of RowMod D

I’ll give it a shot. What’s that do versus setting the row mod manually?