Upload Images to Serial Number

2019-08-20 09:53发布

I have created a custom NOTEID field in InItemLotserial Table to upload images for each serial number in a custom page. It works fine without any issue.

enter image description here

I have wrote a processing page to update the images for existing serial numbers.

protected void AttachImage(InfoINItemLotSerialImport row, INItemLotSerial ser, InventoryItem itm)
    {
        string imageurl = row.ImageSourceUrl;
        string imageType = row.ImageType;
        string sRetVal = string.Empty;
        if (itm != null)
        {
            if (ser != null)
            {
                try
                {
                    WebClient wc = new WebClient();
                    byte[] buffer = wc.DownloadData(imageurl);
                    //MemoryStream ms = new MemoryStream(bytes);

                    string fileName = Path.GetFileName(imageurl);
                    fileName = string.Format("Serial Number attribute ({0} {1})\\{2}", itm.InventoryID, ser.LotSerialNbr, fileName);
                    PX.SM.FileInfo fileinfo = null;
                    PX.SM.UploadFileMaintenance filegraph = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
                    fileinfo = new PX.SM.FileInfo(fileName, null, buffer);
                    fileinfo.IsPublic = true;
                    if (filegraph.SaveFile(fileinfo))
                    {
                        ItemLotSerialMnt oLotSerMnt = PXGraph.CreateInstance<ItemLotSerialMnt>();
                        oLotSerMnt.lotserailrecdata.Current = ser;
                        oLotSerMnt.lotserial.Current = ser;
                        PXNoteAttribute.SetFileNotes(oLotSerMnt.lotserailrecdata.Cache, oLotSerMnt.lotserailrecdata.Current, fileinfo.UID.Value);
                        PXNoteAttribute.SetNote(oLotSerMnt.lotserailrecdata.Cache, oLotSerMnt.lotserailrecdata.Current, "");
                        sRetVal = fileinfo.Name;
                    }

                }
                catch
                {

                }
            }
        }
    }

It uploads the data into UploadFile table and entry looks fine. I can access the image using the URL, but the same is not reflecting in file section of serial page.

How acumatica links the file with the screen?

Update 1

#region UsrNoteID
    public abstract class usrNoteID : PX.Data.IBqlField
    {
    }
    protected Guid? _UsrNoteID;
    [PXNote()]
    public virtual Guid? UsrNoteID
    {
        get
        {
            return this._UsrNoteID;
        }
        set
        {
            this._UsrNoteID = value;
        }
    }
    #endregion

标签: acumatica
1条回答
beautiful°
2楼-- · 2019-08-20 10:39

Accumatica support helped me to fix the issue. I have missed firing persist event to save.

            if (filegraph.SaveFile(fileinfo))
            {
                ItemLotSerialMnt oLotSerMnt = PXGraph.CreateInstance<ItemLotSerialMnt>();
                oLotSerMnt.lotserailrecdata.Current = ser;
                oLotSerMnt.lotserial.Current = ser;
                PXNoteAttribute.SetFileNotes(oLotSerMnt.lotserailrecdata.Cache, oLotSerMnt.lotserailrecdata.Current, fileinfo.UID.Value);
                PXNoteAttribute.SetNote(oLotSerMnt.lotserailrecdata.Cache, oLotSerMnt.lotserailrecdata.Current, "");
                sRetVal = fileinfo.Name;
                oLotSerMnt.Persist();
            }

oLotSerMnt.Persist();

查看更多
登录 后发表回答