how to use search_key variable as field value instead of static value BRO  if(search_key!=''){    dbo.collection("assets").aggregate([     {        "$match": {  $and: [ { status: 1 }, { $or: [ { maker_name : /^.*BRO.*$/i }, { serial_number : /^.*BRO.*$/i  } ] } ] }     },       {       $lookup:        {          from: 'asset_type',          localField: 'asset_type',          foreignField: 'asset_type_id',          as: 'asset_type_details'        }      }     ]).sort({_id:-1}).toArray(function(err, result) {     if (err) throw err;     res.status(200).json({'return_data': result });     db.close();   });  }
6461
I would like to create a String.replaceAll() method in JavaScript and I'm thinking that using a regex would be most terse way to do it.  However, I can't figure out how to pass a variable in to a regex.  I can do this already which will replace all the instances of "B" with "A".  "ABABAB".replace(/B/g, "A");   But I want to do something like this:  String.prototype.replaceAll = function(replaceThis, withThis) {     this.replace(/replaceThis/g, withThis); };   But obviously this will only replace the text "replaceThis"...so how do I pass this variable in to my regex string?
10807
maybe there is a simple answer to my problem:  I have a mssql table ('Person') with a field for first and one for last name. I am coding a Program, where the User should be able to search for persons.     SELECT id, firstname, lastname FROM Person WHERE firstname LIKE   @searchstring + '%' OR lastname LIKE @searchstring + '%'   doesn't work very well, because if the user types 'John W' nothing is found.  For example the person I search for is called John Williams: It should work with searchstrings like 'John W', 'Williams Jo', 'Will' or 'Joh'  Concatenating first and lastname and use %Searchstring% also doesn't work well, because if the searchstring is e.g. 'Will' it should find people who are called Will, Willibald, Williams or Willson or something like that, but not a Person called Goodwill e.g.  And the query should be as fast as possible, because it is executed at every keydown...  edit: forgot to mention that the database must not be changed, because it is from another company.  Thank you for your help.
95683
I am working on a geodatabase. In some of my features, I would like to add a field, in which I will type the values on my own. On this field no duplicates must be allowed. In other words I want it to be a unique value field. I know ObjectID exists to certain uniqueness of the object, but I am working on a relational db and I want this field to be used as primary key.  I have tried adding a field and through access editing it as a "no duplicates allowed" field, but after that, I cannot edit in arcmap and the message "Warning: Unique index on non-OID field" appears.
37203
To all the expert SOSL gurus lurking out there, I thought this will be an interesting one:  I have some SObjects of different types and I want to return their Name values in a single query.  In advance, I know the IDs and the ObjectTypes of the records whose Names I wish to retrieve. It seems 'wrong' to make several SOQL queries even though there aren't too many types.  So being a good platform citizen, I'm using   to retrieve what I need in a single query:  List&lt;List&lt;SObject&gt;&gt; sobjectsLists = Search.query(     'FIND {*?*} RETURNING ' +     'CustomOne__c (Name WHERE Id IN (\'a01000000000000AAA\')),' +     'CustomTwo__c (Name WHERE Id IN (\'a02000000000000AAB\')),' +     'CustomThr__c (Name WHERE Id IN (\'a03000000000000AAC\'))' ); System.debug(sobjectsLists);   But there is one problem: I must specify at least one FIND character and {*?*} doesn't cut it.     System.SearchException search term must be longer than one character: ?   I've tried this to no avail: {*a* OR *b* OR *c* OR *d* OR *e* OR ...} but even if that did work, it wouldn't help in the case that some twisted cowboy puts underscore (_) or god forbid umlaut (ä).  Any guidance on how I can get the Name of all these records at once?
1105
I have never had the need to do this before today, but it doesn't seem like you can make OR queries with EntityFieldQuery, since db_or is used for select queries.  An example would get to all entities that has a date field where the value is null or after today.  Am I missing something or some trick or is this simply not supported?
24554
I have a lookup relationship.  If I just do the following query it works fine:  Sobject c = [select field__r.fieldchild__c from custom_obj where Id = :someId]; system.debug('c:' + c);   However with the following I get an error:  Sobject c = [select field__r.fieldchild__c from custom_obj where Id = :someId]; String c2 = (String) r.getSobject('field__r').get('fieldchild__c');   Error message:     FATAL_ERROR System.NullPointerException: Attempt to de-reference a   null object
120386
I've looked up some of the other Q&amp;As on this topic, however, none have addressed what I am seeking to do.  I have a large data set and I would like to search one field for any values over a certain amount (in this case 20) and if the value is larger than 20, I would like to return a value of 1 in another field, otherwise return a value of 0.  I have tried writing something with no luck.  I am using QGIS 2.8.
96866
I'm using Drupal 8.  What I'm trying to do is:   Access the active node From the node get the value of field_test and assign it to a variable Pass the variable to the drupalSettings function and subsequently to a custom module 'mycustommodule' that triggers an alert   In my content type, I created a field_test field, which is the field I reference in my code. The block is placed on a page of this content type.  This is the code I am using.  mycustomblock.libraries.yml  custom:   version: 1.x   js:     js/custom.js: {}   dependencies:     - core/jquery     - core/drupalSettings   MyCustomBlock.php  &lt;?php /**  * @file  *  */  namespace Drupal\mycustomblock\Plugin\Block; use Drupal\Core\Block\BlockBase;  /**  * Creates a 'Foobar' Block  *  * @Block(  * id = "block_mycustomblock",  * admin_label = @Translation("MyCustomBlock"),  * category = @Translation("Blocks")  * )  */ class MyCustomBlock extends BlockBase {   /**    * {@inheritdoc}    */    public function build() {    // get the variable from field_test   if ($node = \Drupal::routeMatch()-&gt;getParameter('node')) {       $test = $node-&gt;field_test-&gt;value;       $variables['#attached']['library'][] = 'mycustomblock/custom';        $build['#attached']['drupalSettings']['mycustomblock']['test'] = $test;     } }   custom.js  (function ($, Drupal, drupalSettings) {   var testMe = Drupal.settings.mycustomblock.test;   alert(testMe); )(jQuery, drupalSettings);   How can I tell if the JavaScript file is being loaded from the block? I checked in the inspector, and do not see it being loaded when the page with the block on it loads.  Furthermore, how can I properly access the field value and pass it to JavaScript?
90062
I have Opportunity-lookup field on Opportunity (self),  Scenario:   Opportunity A if select Opportunity B using lookup then Opportunity B's same lookup field automatically populate with Opportunity A.   I tried to achieve this using trigger - before insert/update but its failing as:  System.DmlException: Update failed. First exception on row 0 with id 006G000000DHaBlIAL; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 006G000000DHaBl) is currently in trigger Oppy_before_INSUPD, therefore it cannot recursively update itself: []
68635
We are implementing a special type of lookup window in a VisualForce page, which displays a set of potential records a user can select from to populate a Lookup value. As a means to allow users to filter potential selections, we wanted to make use the Lookup Filter properties available when configuring a Lookup field.  The only problem is we don't seem to have any way to dynamically access these filter properties through Apex code. The Describe Field Result does not seem to contain this information, and I haven't been able to find anything in the documentation about it.  Is there no way to access Lookup Filter properties from the Apex Schema methods?
15937
Basically, I want to put first name &amp; surname together into $node->field_par_contact_name  But it gives me warning. (See below)   function partnership_node_presave($node) {   if($node->type == 'partnership') {     $first_name = $node->field_par_contact_first_name['und'][0]['name'];     $surname = $node->field_par_contact_surname['und'][0]['name'];      // https://drupal.org/project/field_hidden     // Hidden variable     $node->field_par_contact_name['und'][0]['value'] = $first_name. ' '. $surname;      // Warning after save: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 173 of .../drupal-7.23/includes/entity.inc   } }   Updated, please see image:
117047
I've to Query a field(e.g X) from one object. Say I'm getting 20 records(LIST)  Now, I've to Query another object using result of above Query using field X  (X field is common to both objects but has different names, say here Field1 and Field2)  What is the easiest way to get data in Developer console ? is below correct   List&lt;string&gt; TP;  List&lt;ObjA &gt; Ds1=  [Select id, name , TPID__C       from QRS_Quote_LOC_Plan_Bundle__c      where Field3 = '1111']; // Field3 is some another field  For(ObjA  b : Ds1 )  TP.add(b.Field1); // storing common field data  List&lt;ObjB&gt; MasterD = [Select id, name from ObjB where Field2 in :TP ]; System.debug(MasterD );
37684
I'm trying create a Map using a name field as key.  Sample code:  Set&lt;String&gt; priceBooksNames = new Set&lt;String&gt;(); priceBooksNames.add('LN-200'); priceBooksNames.add('LN-100');  Map&lt;string,PriceBook2&gt; priceBooks = new Map&lt;string,PriceBook2&gt;([SELECT name,id FROM PriceBook2 WHERE name=:priceBooksNames ]); system.debug(priceBooks.get('LN-100')); //this is returning NULL   I can see on console that setId on map is not getting the name field value.  VARIABLE_ASSIGNMENT [5]|priceBooks|{"serId":1,"value":{"01sb0000000hiqQAAQ":{"serId":2,"value":{"Name":"LN-100 ADULTOS","Id":"01sb0000000hiqQAAQ"}},"01sb0000000hiqGAAQ":{"serId":3,"value":{"Name":"LN-200 EMPRESAS","Id":"01sb0000000hiqGAAQ"}}}}   What I'm going wrong?
9378
Cannot sort on a soql-request in a custom meta data type. When i perform SELECT .. FROM x__mdt WHERE ... ORDER BY x. Then field x cannot be numeric to get a correct order. Change it to a string-field ordering works ok. Playing with ASC/DESC makes no difference!
63620
I have a custom object called entity_c, this has a field called product which is a lookup to product. There could be many records in entity_c for a particular product.  I need to store it in a map with productId as the key and all the records for that product in a list.  Here is what i have till now    Map&lt;id,List&lt;Entity__c&gt;&gt; mapProductEntity = new    Map&lt;id,List&lt;Entity__c&gt;&gt;();   for(Entity__c et : [SELECT name,Field1__c, Product__c, Field2__c FROM Entity__c WHERE Product__c IN : Items ORDER BY Product__c ]{         if (mapProductEntity.containsKey(et.Product__c)){             mapProductEntity.get(et.Product__c).add(new Entity__c(    field__c = et.field1__c,product__c = et.product__c, field2__c = et.value__c ));         }         else{       // Not sure how to add it for first time                    //mapProductEntity.put(et.Product__c, lsEntit.add(new Entitlement__c(   field1__c = et.field1__c,product__c = et.product__c, field2__c = et.value__c )));         }   Is this a right approach? Is there a simpler way to do it?
50717
I want to do simple thing - I want to iterate over list of two objects and use displayColumns as dynamic keys to get values from selectList object:  &lt;aura:attribute name="displayColumns" type="String[]"/&gt; &lt;aura:attribute name="selectList" type="Object[]"/&gt;   &lt;table&gt;     &lt;aura:iteration items="{!v.selectList}" var="elem"&gt;     &lt;tr&gt;         &lt;aura:iteration items="{!v.displayColumns}" var="col"&gt;             &lt;td&gt;{!elem[col]}&lt;/td&gt;         &lt;/aura:iteration&gt;     &lt;/tr&gt;     &lt;/aura:iteration&gt; &lt;/table&gt;   In pure JS I would do: elem[col.value], but in lightning compiler returns:      expecting a positive integer, found 'col' at column 6 of expression:   elem[col.value]: Source   Is there any workaround without creating proper object structure in controller?
87162
I have contact object and Registration Custom Object.  I want to list the registration object fields in contact object using relationship as follows:  SELECT id, name, (SELECT id,name FROM Registrations__r) FROM Contact;   I want to do the same thing using SOSL. is that Possible? I did something like this for Contact fields.  FIND 'searchText' IN ALL FIELDS RETURNING Contact(name,Email);   doesnot know how to use registration object fields here...