Answers.Body: <p>You can use API4 to fetch the Options or value of the option</p>
  <pre><code>$optionValue = \Civi\Api4\OptionValue::get()
    -&gt;addSelect('value')
    -&gt;addWhere('name', '=', 'Completed')
    -&gt;addWhere('option_group_id:name', '=', 'contribution_status')
    -&gt;execute()
    -&gt;first()['value'];
  
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-21T16:56:39.947Z
Answers.LastActivityDate: 2023-04-21T16:56:39.947Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I am trying to fix problems in an extension that relies on the deprecated (now removed) <code>CRM_Core_OptionGroup::getValue</code> but am unsure of the details of the new code.</p>
  <p>The Developed Docs give useful details of the suggested replacement, e.g. (<code>CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status', 'Completed')</code>): <a href="https://docs.civicrm.org/dev/en/latest/framework/pseudoconstant/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/framework/pseudoconstant/</a></p>
  <ul>
  <li>How do I identify the relevant BAO name for this, however?</li>
  <li>And what is the appropriate replacement for <code>CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL);</code>?</li>
  </ul>
  <p>Is there any developer documentation about how to replace deprecated methods in general?</p>
  
Tags: <extension>
Title: How to replace deprecated CRM_Core_OptionGroup::getValue with CRM_Core_PseudoConstant::getKey
ThreadText: # How to replace deprecated CRM_Core_OptionGroup::getValue with CRM_Core_PseudoConstant::getKey
  
  (Asked by: username_0 on 2023-04-21)
  
  I am trying to fix problems in an extension that relies on the deprecated (now removed) `CRM_Core_OptionGroup::getValue` but am unsure of the details of the new code.
  
  The Developed Docs give useful details of the suggested replacement, e.g. (`CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status', 'Completed')`): <https://docs.civicrm.org/dev/en/latest/framework/pseudoconstant/>
  
  * How do I identify the relevant BAO name for this, however?
  * And what is the appropriate replacement for `CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL);`?
  
  Is there any developer documentation about how to replace deprecated methods in general?
  
  **Tags:** extension
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-04-21. Score: 1
  
  You can use API4 to fetch the Options or value of the option
  
  ```
  $optionValue = \Civi\Api4\OptionValue::get()
    ->addSelect('value')
    ->addWhere('name', '=', 'Completed')
    ->addWhere('option_group_id:name', '=', 'contribution_status')
    ->execute()
    ->first()['value'];
  
  ```
  
  
  ---
  
  