二开案例.webapi.根据formid得到表单的entry信息(主键、单据状态字段、单据编号字段、单据类型字段)

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:2

二开案例.webapi.根据formid得到表单的entry信息(主键、单据状态字段、单据编号字段、单据类型字段)

该功能可以通过接口的方式获得表单的关键信息,十分有用。

废话不多说直接上代码

using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.ServiceFacade.KDServiceFx;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using Kingdee.BOS.WebApi.ServicesStub;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;

namespace scjr.extend.plugin.ly.lyproject
{
    [Kingdee.BOS.Util.HotUpdate]
    class fdatatowebapidatatable : AbstractWebApiBusinessService
    {
        public fdatatowebapidatatable(KDServiceContext context)
            : base(context)
        { }
        private string _formId = string.Empty;

        private FormMetadata _formMetadata;

        private JObject _json_info;

        public object getWebApiData(string param)
        {

            try
            {
                _json_info = JObject.Parse(param);
                var ctx = KDContext.Session.AppContext;
                if (ctx == null)
                {
                    // 会话超时,需重新登录
                    return new
                    {
                        isSuccess = false,
                        message = "会话超时,请重新登录"
                    };
                }
                this._formId = String.Format("{0}", _json_info["formid"]);
                _formMetadata = FormMetaDataCache.GetCachedFormMetaData(ctx, _formId);
                List<Entity> entrys = _formMetadata.BusinessInfo.Entrys;
                List<object> results = new List<object>();
                var bus = _formMetadata.BusinessInfo;
                foreach (Entity ent in entrys)
                {
                    if (ent.GetType().Name.EqualsIgnoreCase("HeadEntity"))
                    {
                        results.Add(new
                        {
                            pkname = ent.EntryPkFieldName,
                            tablename = ent.TableName,
                            entryname = ent.EntryName,
                            entrytype = ent.GetType().Name,
                            billnoname = bus.GetBillNoField().Name[2052],
                            billnofieldname = bus.GetBillNoField().FieldName,
                            billstatusname = bus.GetBillStatusField().Name[2052],
                            billstatusfieldname = bus.GetBillStatusField().FieldName,
                            billtypename = bus.GetBillTypeField().Name[2052],
                            billtypefieldname = bus.GetBillTypeField().FieldName
                        });
                        continue;
                    }
                    results.Add(new
                    {
                        pkname = ent.EntryPkFieldName,
                        tablename = ent.TableName,
                        entryname = ent.EntryName,
                        entrytype = ent.GetType().Name,
                        entrytypeid = ent.EntityType
                    });
                }
                return new
                    {
                        isSuccess = true,
                        message = "",
                        data = results

                    };

            }
            catch (Exception e)
            {
                return new
                {
                    isSuccess = false,
                    message = e.Message
                };
            }


        }



    }
}

效果如下图:

image.webp

响应结果:

{
"isSuccess": true,
"message": "",
"data": [
{
"pkname": "FID",
"tablename": "T_STK_STKTRANSFERIN",
"entryname": "STK_STKTRANSFERIN",
"entrytype": "HeadEntity",
"billnoname": "单据编号",
"billnofieldname": "FBILLNO",
"billstatusname": "单据状态",
"billstatusfieldname": "FDOCUMENTSTATUS",
"billtypename": "单据类型",
"billtypefieldname": "FBILLTYPEID"
},
{
"pkname": "FEntryID",
"tablename": "T_STK_STKTRANSFERINENTRY",
"entryname": "STK_STKTRANSFERINENTRY",
"entrytype": "EntryEntity",
"entrytypeid": 1
},
{
"pkname": "FDetailID",
"tablename": "T_STK_STKTRANSFERINSERIAL",
"entryname": "STK_STKTRANSFERINSERIAL",
"entrytype": "SNSubEntryEntity",
"entrytypeid": 1
},
{
"pkname": "FLinkId",
"tablename": "T_STK_STKTRANSFERINENTRY_LK",
"entryname": "FSTKTSTKRANSFERINENTRY_Link",
"entrytype": "SubEntryEntity",
"entrytypeid": 2
}
]
}

制作不易,谢谢大家收藏、点赞、关注

二开案例.webapi.根据formid得到表单的entry信息(主键、单据状态字段、单据编号字段、单据类型字段)

该功能可以通过接口的方式获得表单的关键信息,十分有用。废话不多说直接上代码using Kingdee.BOS.Core.Metadata;using Kingdee.BOS.Core.M...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息