+ Start a Discussion
Peter BölkePeter Bölke 

Submitted name filled with +

Hello,

i have an related list on contacts for an custom object. Until Summer 18 new new button submitted the contact.id, but its submits the name. And spaces are filled with +. Like: 
Name: Peter Boelke
Submitted: Peter+Boelke

I have dialog which parses the url String, early i got the ID from it, now i need to change to work with the name. But because of the replacement it doesnt really work.
ich do "Peter+Boelke".replace('+', ' ')  its ok
but "Peter+Boelke+somewhat".replace('+', ' ') it returns Peter Boelke+somewhat

How can i solve my matter?
Part of my script
<script type="text/javascript">
        sforce.connection.sessionId = '{!$Api.Session_ID}';
    var conn = new jsforce.Connection({ accessToken: '{!$Api.Session_Id}' });
    var url_string = window.location.href;
    var url = new URL(url_string);
    console.log(url);
    var c = url.searchParams.get('href');
    var contact = window.location.search.substr(1).split('&')[1].split('=')[1].replace('+', ' ');
    console.log(contact);
    var queryCon = "SELECT Id, Name, Account.Name from Contact WHERE Name LIKE '" + contact + "'";
    var recordsCon = sforce.connection.query(queryCon).getArray('records');
    console.log(recordsCon[0].Id);
    var query = "SELECT Warengruppe__c, Kontakt__c from Warengruppen_Zuordnung__c WHERE Kontakt__c = '" + recordsCon[0].Id + "'"; 
    var records = sforce.connection.query(query).getArray('records');
    var selKeys;
    var unselKeys = [];
    var path = '/services/data/v41.0';
    var queryCon = "SELECT Name, Account.Name from Contact WHERE Name = '" + contact + "'";

</>

 
Best Answer chosen by Peter Bölke
Narender Singh(Nads)Narender Singh(Nads)
Hi Peter,

Use this:
"Peter+Boelke+somewhat".replace(/[+]/g, ' ');
 

All Answers

Narender Singh(Nads)Narender Singh(Nads)
Hi Peter,

Use this:
"Peter+Boelke+somewhat".replace(/[+]/g, ' ');
 
This was selected as the best answer
Peter BölkePeter Bölke
Hello Narender,

that works...but i figures out the the url havent changed dramatically. Just changed:
 
var contact = window.location.search.substr(1).split('&')[1].split('=')[1]);

to
var contact = window.location.search.substr(1).split('&')[2].split('=')[1];

​but thanks
Narender Singh(Nads)Narender Singh(Nads)
You're welcome. :)