AnsweredAssumed Answered

Create custom field just like tag

Question asked by Adnan Ahmad on Dec 12, 2019
Latest reply on Dec 12, 2019 by Logamurugan Pilavadi

Hi. 

I am trying to create a new field just like "tag" under the Account module. 

I created the field via studio under the "Account" module. My new field name is "auto_name_c" and the field type is "multi-select". In the multi select i selected "drop down list: account type". (I want an empty list)

then I created a new js file "auto_name.js" and added this file via "js grouping".

I am trying to create a new field that fetches data just like the "tag" field under account module.

I am facing the following issues here. 

1) when I click on my results "li". Nothing is adding in the field.

2) I want to add an empty drop-down list (before my ajax call). 

3) Is the following approach is correct? if not then what will be?

 

Thanks in advance. 

Here is my file "auto_name.js"

 

 

(function(app){
    $document ).on"keyup"'[data-fieldname="auto_name_c"] input[type="text"]'function() {
        $.ajax({
            beforeSendfunction(request) {
                request.setRequestHeader("OAuth-Token"SUGAR.App.api.getOAuthToken());
                $(".select2-results").empty();
            },
            url: "rest/v10/ab_AutoName/filter",
            data: { "filter[0][name][$starts]"$('input[name="auto_name_c"]').val(), "fields""id,name"max_num: 50000 },
            dataType: "json",
            type: "GET",
            successfunction(data) {
                console.log("Adnan:",data);
                let li = '';
                $.map(data.records, function(obj) {
                    li +='<li class="select2-results-dept-0 select2-result select2-result-selectable" role="presentation">';
                    li +='  <div class="select2-result-label" role="option"><span class="select2-match"></span>'+obj.name+'</div>';
                    li +='</li>';
                });
                $(".select2-results").append(li);
 
            }
        });
    });
})(SUGAR.App);

Attachments

Outcomes