AX2009 C#客户端通过Web service批量审核工作流(二)

配置好Web service后就可以开发和发布Service

先创建Class\WorkflowApprovalServiceClass,添加方法dataList,返回当前用户需要审批的工作流记录ID

public str  dataList()
{
    WorkflowWorkItemTable       workItem;
    container   con;

    while select  RecId from workItem where workItem.UserId==curuserid()
                                        &&  workItem.Status==WorkflowWorkItemStatus::Pending
                                        &&  workItem.Type==WorkflowWorkItemType::WorkItem
        con+=workItem.RecId;
    if(con)
        return con2str(con);
    else
        return "";
}

AX2009返回值的类型只支持以下几种简单类型

private static boolean validateParamType(Types _type, int _typeId)
{
    boolean isValid;
    SysDictType dictType;
    SysDictClass dictClass;
    ;
    if(_type == Types::Class)
    {
        dictClass = new SysDictClass(_typeId);

        // Check if class implements AifXmlSerializable.
        isValid = dictClass.isImplementing(classnum(AifXmlSerializable));
    }
    else    // built-in type.
    {
        switch(_type)
        {
            case(Types::UserType):
            {
                dictType = new SysDictType(_typeId);
                isValid = AifServiceGenerationManager::validateParamType(dictType.baseType(), _typeId);
                break;
            }
            case(Types::String):
            case(Types::RString):
            case(Types::VarString):
            case(Types::Date):
            case(Types::UtcDateTime):
            case(Types::Guid):
            case(Types::Integer):
            case(Types::Int64):
            case(Types::Enum):
            case(Types::Real):
            case(Types::void):
            {
                isValid = true;
                break;
            }
            case(Types::AnyType):
            case(Types::BLOB):
            case(Types::Container):
            case(Types::Record):
            case(Types::Time):
            default:
            {
                isValid = false;
            }
        }
    }

    return isValid;
}

添加审批方法批准和拒绝

public void updateApprove(recId    _recid,str _comment="")
{
    WorkflowWorkItemTable _workItem=WorkflowWorkItemTable::findRecId(_recid);
    ;

    WorkflowWorkItem::takeAction(_workItem.Id,
                                        WorkflowWorkItemActionManager::findOutcomeNameForMenuItem(_workItem,
                                                                                                "PurchApprovalApprove",//工作流批准的菜单项
                                                                                                false),
                                                                                                _comment,
                                                                                                curuserid());
}
public void updateReject(recId    _recid,str _comment="")
{
    WorkflowWorkItemTable _workItem=WorkflowWorkItemTable::findRecId(_recid);
    ;

    WorkflowWorkItem::takeAction(_workItem.Id,
                                        WorkflowWorkItemActionManager::findOutcomeNameForMenuItem(_workItem,
                                                                                                "PurchApprovalReject",//工作流拒绝菜单项
                                                        false), _comment, curuserid()); }

再添加一些需要显示参考的字段方法就可以了

接下来就到AOT-Services中增加一个Service/WorkflowApprovalService

将属性中的Class指向上面创建的Class/WorkflowApprovalServiceClass

另外还需要添加securityKey,否则在客户端调用时会出错

然后打开Service/WorkflowApprovalService,在operations右键添加operation,系统会自动将Class上符合要求的方法显示出来,添加需要的方法,保存即可

最后是打开上一篇中的设置服务,刷新后选择服务发布就可以了

 

posted @ 2015-10-20 14:28  止在入门  阅读(620)  评论(3编辑  收藏  举报