Skip to main content

Featured

[XrmToolBox] Use FetchXML Builder

FetchXML Installation : XrmToolBox 1. Open XrmToolBox And Find FetchXML Builder 2. Start FetchXML Builder 3. Click the fetch from node 사용은 Top 또는 Paging 둘 중 하나만 가능 Paging size : 한 페이지에 보여줄 레코드 개수 Dstinct : 페이지에 보여지는 레코드 중복 제거 No-lock : 테이블 lock 거는 것을 풀어줌 (조회 할 때 퍼블리시되지 않은 값도 들어올 수 있음) Page : 페이지 (미입력시 1 페이지) 4. Click entity form node 조회할 Entity Name을 선택 후, Select Attributes 클릭 조회할 Entity의 Attirbute를 선택하여 확인 link-entity 클릭 Relationship을 클릭하여 링크할 관계 선택 후 결과

CRM add filter duplicated field into javascript

I Found some problem on lookup field. it is adding filter each duplicated field that change condition when select optionset field.

just set value it worked normally. but add filter worked only one duplicated field(i have 3 duplicated field)

here's my problem code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function onChangeFieldSetting(){
    var modeValue;
    if(Xrm.Page.getAttribute("new_p_modes").getValue() != null)
        modeValue = parseInt(Xrm.Page.getAttribute("new_p_modes").getValue());
    if(modeValue == 100000000){ //Korea
        Xrm.Page.getControl("new_l_korea").addPreSearch(addFilter);
    } else if(modeValue == 100000001) { //USA
        Xrm.Page.getControl("new_l_usa").addPreSearch(addFilter);
    }
}
function addFilter(){
    if(Xrm.Page.getAttribute("new_l_organization"!= null && Xrm.Page.getAttribute("new_l_organization").getValue() != null) {
        var organizationName = Xrm.Page.getAttribute("new_l_organization").getValue()[0].name.toString().toUpperCase();
        var attributeName = "";
        var displayViewName = "";
        
        switch(organizationName){
            case "SALES"//Team
                attributeName = "new_chk_sales";
                displayViewName = "Sales";
                break;
            case "Support"//Team (Q&A)
                attributeName = "new_";
                displayViewName = "Sales";
                break;
        }
        var modeValue;
        if(Xrm.Page.getAttribute("new_p_modes").getValue() != null)
            modeValue = parseInt(Xrm.Page.getAttribute("new_p_modes").getValue());
        var fetchXml = getAccountSearchFilterbyOrg(modeValue,attributeName);
        var layoutXml = getAccountSearchFilterbyOrgLayout();
        if(modeValue == 100000000){ //Korea
            Xrm.Page.getControl("new_l_korea").addCustomView("{00000000-0000-0000-0000-000000000001}""account", displayViewName, fetchXml, layoutXml, true);
        } else if(modeValue == 100000001) { //USA
            Xrm.Page.getControl("new_l_usa").addCustomView("{00000000-0000-0000-0000-000000000001}""account", displayViewName, fetchXml, layoutXml, true);
        }
    }
}
         
    
cs

anyway, it work only one duplicated field. unfortunately i don't have picture. just imagine.

so i fixed that get all duplicated field and added filter.

1
2
3
4
var korea = Xrm.Page.getAttribute("new_l_korea").controls;
korea.forEach(function(entry){
    entry.addPreSearch(function() { addFilter(entry); });
});
cs

here's fixed code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function onChangeFieldSetting(){
    var modeValue;
    if(Xrm.Page.getAttribute("new_p_modes").getValue() != null)
        modeValue = parseInt(Xrm.Page.getAttribute("new_p_modes").getValue());
    if(modeValue == 100000000){ //Korea
        var korea = Xrm.Page.getAttribute("new_l_korea").controls;
        korea.forEach(function(entry){
            entry.addPreSearch(function() { addFilter(entry); });
        });
    } else if(modeValue == 100000001) { //USA
        var usa= Xrm.Page.getAttribute("new_l_usa").controls;
        usa.forEach(function(entry){
            entry.addPreSearch(function() { addFilter(entry); });
        });
    }
}
function addFilter(fieldcontrol){
    if(Xrm.Page.getAttribute("new_l_organization"!= null && Xrm.Page.getAttribute("new_l_organization").getValue() != null) {
        var organizationName = Xrm.Page.getAttribute("new_l_organization").getValue()[0].name.toString().toUpperCase();
        var attributeName = "";
        var displayViewName = "";
        
        switch(organizationName){
            case "SALES"//Team
                attributeName = "new_chk_sales";
                displayViewName = "Sales";
                break;
            case "Support"//Team (Q&A)
                attributeName = "new_";
                displayViewName = "Sales";
                break;
        }
        var modeValue;
        if(Xrm.Page.getAttribute("new_p_modes").getValue() != null)
            modeValue = parseInt(Xrm.Page.getAttribute("new_p_modes").getValue());
        var fetchXml = getAccountSearchFilterbyOrg(modeValue,attributeName);
        var layoutXml = getAccountSearchFilterbyOrgLayout();
        if(modeValue == 100000000){ //Korea
            fieldcontrol.addCustomView("{00000000-0000-0000-0000-000000000001}""account", displayViewName, fetchXml, layoutXml, true);
        } else if(modeValue == 100000001) { //USA
            fieldcontrol.addCustomView("{00000000-0000-0000-0000-000000000001}""account", displayViewName, fetchXml, layoutXml, true);
        }
    }
}
cs

anyway if you have a trouble like this. try get all duplicated controls first, and add a filter.

Comments

Popular Posts