Js 案例,排序和比较

通过某一个值排序输出

 if (json.Entity[0].Attributes.find(f => f.Key == "ssss_confirmed_by") != undefined) {
                SDK.CrmRest.retrieveMultipleRecords("SystemUser", "?$select=teammembership_association/Name,teammembership_association/ssss_rank,teammembership_association/TeamId&$expand=teammembership_association&$filter=SystemUserId eq (guid'" + json.Entity[0].Attributes.find(f => f.Key == "ssss_confirmed_by").Value.Id + "')", function (results) { 
                    confirmteam = getSystemUserTeam(results[0].teammembership_association);        
                }, function (error) {
                    Xrm.Utility.alertDialog(error.message);
                }, function () {
                    //On Complete - Do Something
                });
            }

 

function getSystemUserTeam(object) {
            var list = object;
            if (list.results.length == 1) {
                return list.results[0].Name;
            }
            else if (list.results.length > 1) {
                let srr = list.results;
                srr.forEach((item, index, srr) => {
                    //null remove
                    if (item.ssss_rank === null) {
                        srr.splice(index, 1)
                    }
                });
                //排序
                list.results.sort(function (a, b) {
                    return a.ssss_rank - b.ssss_rank
                })
                return  list.results[0].Name;
            }
        }

比较,是否包含数值

//隐藏sub-gridd[+]按钮
function ShowRoleForBaidu_Potential() {
    return fnHiddenSubGridButton("crms_potential_casse_status", [722890003, 722890004, 722890005], false);
}
function fnHiddenSubGridButton(FieldName, OptionValues, InvertResult) {
    var ret = true;
    if (Xrm.Page.getAttribute(FieldName) != null) {
        var FieldValue = Xrm.Page.getAttribute(FieldName).getValue();
        if (OptionValues.indexOf(FieldValue) == -1) ret = true;
        else ret = false;
    }
    if (InvertResult) ret = !ret;
    return ret;
}

 

posted @ 2021-06-03 10:09  没有狐狸的南墙  阅读(59)  评论(0编辑  收藏  举报